【发布时间】:2013-02-28 22:08:26
【问题描述】:
谁能告诉我如何在 XAML 中将源设置为来自 Resource 的图像。目前我有
<Image x:Name="img" Panel.ZIndex="1" Source="D:\Img100.jpg" Stretch="Uniform"/>
我希望图像源来自资源。
谢谢。
【问题讨论】:
标签: wpf image wpf-controls
谁能告诉我如何在 XAML 中将源设置为来自 Resource 的图像。目前我有
<Image x:Name="img" Panel.ZIndex="1" Source="D:\Img100.jpg" Stretch="Uniform"/>
我希望图像源来自资源。
谢谢。
【问题讨论】:
标签: wpf image wpf-controls
首先,您必须使用 BuildAction Resource 将图像包含在您的项目中
然后你可以直接在你的Image中使用它
<Image Source="Img100.jpg"/>
或者做一个可复用的图片资源
App.xaml(或其他资源字典)
<Application.Resources>
<BitmapImage x:Key="myImage" UriSource="Img100.jpg" />
</Application.Resources>
元素:
<Image Source="{StaticResource myImage}" />
【讨论】: