【发布时间】:2017-10-20 07:56:08
【问题描述】:
我在将图像缩略图数据绑定到 xaml 上的图像时遇到了一些问题,所以我做了一个简单的示例,向您展示我想要获得的只是一个文件的简单缩略图,并将其显示到 xaml 上的图像元素.
我在过去的 uwp 应用程序中处理了很多缩略图,我不明白我在这里做错了什么。
C# 代码
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
protected async override void OnNavigatedTo(NavigationEventArgs e)
{
img.Source = await GetIt();
}
public async Task<BitmapImage> GetIt()
{
var files=await KnownFolders.VideosLibrary.GetFilesAsync();
var thumb=await files[0].GetThumbnailAsync(Windows.Storage.FileProperties.ThumbnailMode.VideosView);
var bitm = new BitmapImage();
bitm.SetSource(thumb);
return bitm;
}
}
XAML 代码
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Image Name="img"/>
</Grid>
输出只是一个空白页
注意我尝试在 return bitm 上设置断点,但这个断点永远不会执行。我还注意到 GetAllFiles() 方法返回一个 System.__ComObject,实际上它应该返回一个 IReadOnlyList<StorageFile>。
【问题讨论】:
-
调试您的应用程序并观察 System.UnauthorizedAccessException 的输出窗口
-
我允许 VideoLibrary 来自 capibilities 所以没有例外
标签: c# image xaml thumbnails uwp-xaml