我正在使用 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?