【问题标题】:Image Binding with UriSource from the user Picture library Windows 8使用用户图片库 Windows 8 中的 UriSource 进行图像绑定
【发布时间】:2014-02-13 21:34:10
【问题描述】:

我似乎无法使用 UriSource 绑定从图片库中将图像显示在网格视图中

这是 XAML 绑定:

                    <Border Background="{ThemeResource ListViewItemPlaceholderBackgroundThemeBrush}">
                        <Image Stretch="UniformToFill">
                            <Image.Source>
                                <BitmapImage UriSource="{Binding Path=ImageUri}" DecodePixelWidth="200"  />
                            </Image.Source>
                        </Image>
                    </Border>

这是我输入的示例 URI:

{C:\Users\Name\Pictures\桌面壁纸\35bd31e7-5e4d-43c4-b704-136ee0b5b705.jpg}

【问题讨论】:

    标签: c# windows-8 microsoft-metro windows-8.1


    【解决方案1】:

    您不能在 Windows 8 应用商店应用中传递绝对路径。 尝试使用 FileOpenPicker 将图片加载到 FileRandomAccessStream 等流中 创建一个 BitmapImage 并将流设置为位图图像的源,并将其作为图像源分配给您的图像控件。

    BitmapImage bitmapImage = new BitmapImage();
    if (file != null)
    {
        FileRandomAccessStream stream = (FileRandomAccessStream)await file.OpenAsync(FileAccessMode.Read);
        bitmapImage.SetSource(stream);
    }
    
    ImageUri = bitmapImage;
    

    【讨论】:

    • 就我而言,这不是一个可接受的选择。来吧,这不可能是唯一的方法......
    猜你喜欢
    • 2010-09-06
    • 2011-03-10
    • 2013-09-23
    • 1970-01-01
    • 2011-12-26
    • 2023-03-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多