【发布时间】:2013-12-15 22:26:03
【问题描述】:
这段代码有什么问题?当我在代码中将 XAML 中的图像源绑定到 firstimage 时,为什么 firstimage 没有显示在 XAML 页面上? 包含代码的类不是分部类。
if (ImagesAsSource[realty.ObjectId].Count == 0)
//private static Uri _baseUri = new Uri("ms-appx:///");
{
Uri img = new Uri(_baseUri, "Assets/back.jpg");
BitmapImage result = new BitmapImage();
result.UriSource = img;
// firstimage is type of ImageSoure
firstimage =result;
}
//I tried this:
//private static Uri _baseUri = new Uri("ms-appx:///");
{
Uri img = new Uri(_baseUri, "Assets/back.jpg");
BitmapImage result = new BitmapImage(img );
// firstimage is type of ImageSoure
firstimage =result;
}
【问题讨论】:
-
问题是你试图从 URI 字符串创建 BitmapImage。
-
解决办法是什么?
-
你可以试试答案中的代码
-
@Valin 从
Uri(不是 URI 字符串)创建 BitmapImage 不是问题,而是创建 BitmapImage 的正确方法。 -
@user3105491 请显示您绑定到
firstimage的XAML。您确定firstimage是公共财产吗?
标签: c# xaml windows-runtime