【发布时间】:2010-07-05 14:51:42
【问题描述】:
我正在使用 BitmapImage 类在 WPF 中加载图像。当我为 UriSource 提供绝对路径时,我的代码可以完美运行,但当我尝试使用相对路径时却不行。
我的 XAML 是:
<Image Width="50" Name="MemberImage" HorizontalAlignment="Left">
<Image.Source>
<BitmapImage DecodePixelWidth="50" UriSource="questionmark.jpg" />
</Image.Source>
</Image>
questionmark.jpg 被添加到项目中,并将资源的构建操作和复制到输出目录设置为始终复制。我得到的错误是“文件 [文件名] 不是项目的一部分,或者它的‘构建操作’属性未设置为‘资源’”。当我为 UriSource 使用绝对路径但显然不行时,这有效。
我应该如何在 XAML 中定义我的 UriSource?
【问题讨论】:
标签: wpf uri bitmapimage