【发布时间】:2014-05-22 05:28:45
【问题描述】:
我有两个 .png 文件添加到我的资源中,我需要在绑定时访问它们的 Uri。
我的xaml代码如下:
<Grid>
<Image>
<Image.Source>
<BitmapImage DecodePixelWidth="10" UriSource="{Binding Path=ImagePath}"/>
</Image.Source>
</Image>
</Grid>
而使用 ImagePath 的 binding 代码是:
ImagePath = resultInBinary.StartsWith("1") ? Properties.Resources.LedGreen : Properties.Resources.ledRed;
然而
Properties.Resources.LedGreen
返回一个 Bitmap 而不是 String 包含该特定图像的 Uri。
我只想知道如何提取该值,而无需在其存储的目录中处理图像的路径。 (老实说,我不确定这样做是否正确,因为我在网上找不到任何类似的情况)。
如果有的话,请告诉我是否有比我尝试使用的首选方法。
【问题讨论】:
标签: c# wpf xaml binding resources