代码之家  ›  专栏  ›  技术社区  ›  Relaxo

Avalonia Ui等价于ImageResource

  •  1
  • Relaxo  · 技术社区  · 6 年前

    我尝试用AvaloniaUi定义一个ImageSource。在WPF中我是这样做的:

    <ResourceDictionary
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
       <ImageSource x:Key="Icon">path/to/image/image.png</ImageSource>
    </ResourceDictionary>
    

    然后像这样引用它:

    <Image Source="{StaticResource Icon}"/>
    

    我怎样才能在阿瓦隆尼亚存档?

    1 回复  |  直到 6 年前
        1
  •  2
  •   kekekeks    6 年前
    <UserControl xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:imaging="clr-namespace:Avalonia.Media.Imaging;assembly=Avalonia.Visuals">
        <UserControl.Resources>
            <imaging:Bitmap x:Key="MyBitmap">
                <x:Arguments><x:String>icon.png</x:String></x:Arguments>
            </imaging:Bitmap>
        </UserControl.Resources>
           <Image Source="{StaticResource MyBitmap}"
                   Width="100" Height="200"
                   Stretch="None"/>
    </UserControl>
    

    请注意,这只适用于物理路径,因为不再涉及转换器。