我在资源上有一个图标,它的关键是:xxx
我想将它绑定(bind)到 xaml 中的图像..
1:
<Image Source="{x:Static p:Resources.xxx}"></Image>
2:
<Image>
<Image.Source>
<BitmapImage UriSource="{Binding x:Static p:Resources.xxx}"/>
</Image.Source>
</Image>
3:
<Image Source=" {Binding x:Static p:Resources.xxx,Converter={StaticResource IconToBitmap_Converter}}"></Image>
4:
<Image>
<Image.Source>
<BitmapImage UriSource="{Binding x:Static p:Resources.xxx,Converter={StaticResource IconToBitmap_Converter}}"/>
</Image.Source>
</Image>
以上方法都行不通,我该怎么做呢?
最佳答案
首先,您必须将您的图像添加到解决方案资源管理器中的资源文件中。接下来,您必须将 Image 的 Build Action 设置为 Resource,然后您可以在 XAML 代码中使用它,如下所示:
<UserControl>
<UserControl.Resources>
<ResourceDictionary>
<BitmapImage x:Key="name" UriSource="Resources/yourimage.bmp" />
</ResourceDictionary>
</UserControl.Resources>
<Grid>
<Image Source="{StaticResource name}"/>
</Grid>
</UserControl>
关于wpf - 通过绑定(bind) -WPF 从资源中显示图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14751525/