I can't seem to get images to display in a gridview from the picture library using the UriSource binding

Here is the XAML binding:

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

and this is an example URI that I am feeding into it:

{C:\Users\Name\Pictures\Desktop Wallpapers\35bd31e7-5e4d-43c4-b704-136ee0b5b705.jpg}

有帮助吗?

解决方案

You can't pass an absolute path in Windows 8 store apps. Try to load your picture into a stream such as FileRandomAccessStream using FileOpenPicker Create a BitmapImage and set the stream as source for the bitmap image and assign it as image source to your image control.

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

ImageUri = bitmapImage;
许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top