在Windows 8 Metro C#中显示StorageFile

Lgn*_*Lgn 4 c# microsoft-metro windows-8

我想在资产管理系统的UI上显示一个图像文件.我设法将项目存储为StorageFile.我该如何显示它?我试图在XAML <Image>标签的Source中显示它.是否有可能StorageFile转向Image

string path = @"Assets\mypicture.png";
StorageFile file = await InstallationFolder.GetFileAsync(path);
Run Code Online (Sandbox Code Playgroud)

sof*_*arn 9

试试这个功能

public async Task<Image> GetImageAsync(StorageFile storageFile)
{
        BitmapImage bitmapImage = new BitmapImage();
        FileRandomAccessStream stream = (FileRandomAccessStream)await storageFile.OpenAsync(FileAccessMode.Read);
        bitmapImage.SetSource(stream);
        Image image = new Image();
        image.Source = bitmapImage;
        return image;
}
Run Code Online (Sandbox Code Playgroud)