图像不会加载到Xaml上

时间:2016-10-26 07:28:50

标签: c# xaml uwp win-universal-app windows-10-universal

我在图像加载方面遇到了麻烦(只在这台电脑上,其他的就好了)

我尝试了几种方法来放置图像

 <Image 
        MinWidth="190"
        Stretch="Fill"
        MinHeight="190"    
        Source="{Binding ImagePath, Converter={StaticResource UriToImageConverter}}">
        <!--If you use my way in answer you need replace Source like this-->
        Source="{Binding Image}"><!--Bitmapimage property in model-->
 </Image>

只有当我按照&#39; ms-appx&#39;但在目标中我需要使用&#39; Binding&#39;它的工作在其他电脑上没有任何麻烦,但在这里,我有&#34;透明&#34;页面上的图片

1 个答案:

答案 0 :(得分:0)

好的,我只是将图片放到StorageFile并将其复制到本地文件夹并从那里取出并放入我的Model属性

在:

 this.collageimages = await OpenPicker.PickMultipleFilesAsync();
 for (var i = 0; i < this.collageimages.Count; i++)
{
  var stream = await collageimages[i].OpenAsync(FileAccessMode.Read);
  this.image = new BitmapImage();
  await this.image.SetSourceAsync(stream);
}

后:

this.collageimages = await OpenPicker.PickMultipleFilesAsync();
 for (var i = 0; i < this.collageimages.Count; i++)
{
  await this.collageimages[i].CopyAsync(ApplicationData.Current.LocalFolder, "collageImage_"+i+"", NameCollisionOption.ReplaceExisting);
  var tempStorage = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appdata:///local/collageImage_"+i+""));
  var stream = await tempStorage.OpenAsync(FileAccessMode.Read);
  this.image = new BitmapImage();
  await this.image.SetSourceAsync(stream);
}

如果你知道更好的方法,我不认为是最好的答案,请写下来