我有一个项目,我正在从 xml 文件加载相对图像 Uri。我正在加载这样的图像:
if (child.Name == "photo" &&
child.Attributes["href"] != null &&
File.Exists(child.Attributes["href"].Value))
{
Image image = new Image();
image.Source = new BitmapImage(new Uri(child.Attributes["href"].Value, UriKind.RelativeOrAbsolute));
images.Add(image);
}
其中“子”对象是一个 XmlNode,看起来像这样
<photo name="info" href="Resources\Content\test.png"/>
在调试过程中,图像似乎充满了实际图像,但是当我想以任何方式查看它们时,它什么也没有显示。奇怪的是,当我将图像包含在我的项目中时它确实可以工作,但是我不想这样做,因为我使用 xml 文件的目的是因为你必须在更改后重新构建程序,所以它会丢失.