我有两个 .png
文件添加到我的资源中,需要在进行绑定时访问它们的Uri。
我的 xaml
代码如下:
<Grid>
<Image>
<Image.Source>
<BitmapImage DecodePixelWidth="10" UriSource="{Binding Path=ImagePath}"/>
</Image.Source>
</Image>
</Grid>
使用 ImagePath 进行绑定的代码如下:
ImagePath = resultInBinary.StartsWith("1") ? Properties.Resources.LedGreen : Properties.Resources.ledRed;
然而
Properties.Resources.LedGreen
返回一个Bitmap
,而不是包含特定图像的Uri的String
。我只想知道如何提取该值,而无需引用存储在目录中的图片路径(实际上,我不确定这样做是否正确,因为我在网上找不到类似的情况)。
如果有更好的方法可用,请告诉我。
Resource
构建操作将图像文件添加到程序集中。因此它们包含在可执行文件中。 - Clemens