【问题标题】:Avalonia Ui equivalent to ImageResourceAvalonia Ui 相当于 ImageResource
【发布时间】:2018-10-10 09:35:08
【问题描述】:

我尝试使用 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}"/>

如何在 Avalonia 中存档?

【问题讨论】:

    标签: wpf xaml avaloniaui


    【解决方案1】:
    <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>
    

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

    您还可以尝试使用可以接受您自己的图像持有者的附加属性。

    【讨论】:

    • 这行得通,感谢您的快速回答。我将imaging:Bitmap 放在一个单独的.XAML 文件中,在一个Style.Resource 中,它将所有图像放在一起。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多