【问题标题】:Databinding uri source of imagebrushimagebrush的数据绑定uri源
【发布时间】:2015-10-04 13:32:53
【问题描述】:

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

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

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

【问题讨论】:

    标签: xaml data-binding windows-10 win-universal-app


    【解决方案1】:

    使用ms-appx URI scheme

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

    注意写///

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

    【讨论】:

    • 是的,这就是问题所在,实际上我之前也尝试过(从 xaml imagebrush 的源代码复制它),但是里面有一些额外的空间,这就是问题所在。
    【解决方案2】:

    确保设置图像的属性,使其在运行时可用。有时,如果在 Blend 中使用设计时数据,您会在设计时看到图像,但在运行时什么也看不到。原因是图像从未与解决方案的其余部分一起部署。确保每个图像上的 Build Action 设置为 Content,我通常将 Copy to Output Directory 设置为 Copy if Newer。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-02-02
      • 2014-05-01
      • 2015-07-24
      • 1970-01-01
      相关资源
      最近更新 更多