Can anyone show me how can I set source to image from Resource in XAML. Currently I have
任何人都可以告诉我如何从XAML中的资源设置源图像。目前我有
<Image x:Name="img" Panel.ZIndex="1" Source="D:\Img100.jpg" Stretch="Uniform"/>
I want Image Source to be come from Resources.
我希望Image Source来自Resources。
Thanks.
谢谢。
1 个解决方案
#1
27
First you will have to include the image in your project with BuildAction Resource
首先,您必须使用BuildAction Resource将图像包含在项目中
Then you can use it directly in your Image
然后,您可以直接在图像中使用它
<Image Source="Img100.jpg"/>
Or make a reusable resource of the image
或者制作图像的可重用资源
App.xaml (or other resource dictionary)
App.xaml(或其他资源字典)
<Application.Resources>
<BitmapImage x:Key="myImage" UriSource="Img100.jpg" />
</Application.Resources>
Element:
元件:
<Image Source="{StaticResource myImage}" />
#1
27
First you will have to include the image in your project with BuildAction Resource
首先,您必须使用BuildAction Resource将图像包含在项目中
Then you can use it directly in your Image
然后,您可以直接在图像中使用它
<Image Source="Img100.jpg"/>
Or make a reusable resource of the image
或者制作图像的可重用资源
App.xaml (or other resource dictionary)
App.xaml(或其他资源字典)
<Application.Resources>
<BitmapImage x:Key="myImage" UriSource="Img100.jpg" />
</Application.Resources>
Element:
元件:
<Image Source="{StaticResource myImage}" />