我试图用ImageSource定义一个AvaloniaUi。在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保存同样的文件?
发布于 2018-10-10 12:56:42
<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>请注意,这只适用于物理路径,因为不再涉及转换器。
你也可以尝试实验附加的属性,这将接受您自己的图像持有人。
https://stackoverflow.com/questions/52737062
复制相似问题