Imagebrush 的数据绑定 uri 源

Databinding uri source of imagebrush

在我的应用程序中,我将几个属性绑定到自定义用户控件,一切正常,只是图像没有显示。对于绑定,我使用了以下代码:

Categories.Add(new Models.Category { Name = "Pizza", Count= 4, ImageUri = new Uri("Images/pizza.png", UriKind.Relative) });

我也尝试过不同的 urikinds,但图像从未显示过。 会出什么问题?图片在我的解决方案图片文件夹中。

使用 ms-appx URI scheme:

ImageUri = new Uri("ms-appx:///Images/pizza.png");

认真写///.

还要确保图像文件的 Build Action 设置为 Content,如其他答案中所指出的。然而,设置 Copy to Output Directory 似乎没有必要。

请务必设置图像的属性,使其在 运行 时间内可用。有时,如果在 Blend 中使用设计时数据,您会在设计时看到图像,但在 运行 时间内什么也看不到。原因是图像从未与解决方案的其余部分一起部署。确保每个图像上的构建操作都设置为内容,我通常将复制到输出目录设置为如果较新则复制。