Answered by:
Cannot bind a image in GroupedItemsPage

Question
-
Hello Everybody :)
I use a GroupedItemsPage to show some photo. I can bind all text, but only cannot bind image.
I wrote my data structure like :
public class DataStructurePhotoItem : INotifyPropertyChanged { private string title = string.Empty; public string Title { get { return title; } set { title = value; NotifyPropertyChanged("Title"); } } private string subtitle = string.Empty; public string Subtitle { get { return subtitle; } set { subtitle = value; NotifyPropertyChanged("Subtitle"); } } private String imagePath = null; public String ImagePath { get { return imagePath; } set { imagePath = value; NotifyPropertyChanged("ImagePath"); } } private ImageSource image = null; public ImageSource Image { get { if (image == null && imagePath != null) { image = new BitmapImage(new Uri(ImagePath, UriKind.RelativeOrAbsolute)); } return image; } RelativeRelativeOrAbsoluteOrAbsolute { image = value; NotifyPropertyChanged("Image"); ; } } private String description = null; public String Description { get { return description; } set { description = value; NotifyPropertyChanged("Description"); } } #region ProertyChanged public event PropertyChangedEventHandler PropertyChanged; private void NotifyPropertyChanged(String info) { if (PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(info)); } } #endregion }
DataStructure above bind a Standard500x130ItemTemplate:
<DataTemplate x:Key="Standard250x250ItemTemplate"> <Grid HorizontalAlignment="Left" Width="250" Height="250"> <Border Background="{StaticResource ListViewItemPlaceholderRectBrush}"> <Image Source="{Binding Image}" Stretch="UniformToFill" /> </Border> <StackPanel VerticalAlignment="Bottom" Background="{StaticResource ListViewItemOverlayBackgroundBrush}"> <TextBlock Text="{Binding Title}" Foreground="{StaticResource ListViewItemOverlayTextBrush}" Style="{StaticResource TitleTextStyle}" Height="60" Margin="15,0,15,0"/> <TextBlock Text="{Binding Subtitle}" Foreground="{StaticResource ListViewItemOverlaySecondaryTextBrush}" Style="{StaticResource CaptionTextStyle}" TextWrapping="NoWrap" Margin="15,0,15,10"/> </StackPanel> </Grid> </DataTemplate>
And i'm sure that image's Uri is not null. But images are kind of null... Above is the capture :
The result of my code is like below, the Title, SubTitle and Descprition are well binded to the GroupedItemsPage. But the image cannot be binded.
Thanks for your help :)
Wednesday, April 4, 2012 9:19 PM
Answers
-
I find that maybe i must use code below because of low version of Metro....
BitmapImage bmp = new BitmapImage(); StorageFolder picturesFolder = KnownFolders.PicturesLibrary; StorageFile image1File = await picturesFolder.GetFileAsync(fileName); bmp.SetSource(await image1File.OpenAsync(FileAccessMode.Read));
- Marked as answer by ComiscienceHelloWorld Friday, April 6, 2012 11:02 AM
Friday, April 6, 2012 10:08 AM
All replies
-
Does "ref new" works?Thursday, April 5, 2012 1:17 AM
-
Does "ref new" works?
Hi, JackyGao
What do you mean "ref new"?
Thanks
Thursday, April 5, 2012 8:00 AM -
I find that maybe i must use code below because of low version of Metro....
BitmapImage bmp = new BitmapImage(); StorageFolder picturesFolder = KnownFolders.PicturesLibrary; StorageFile image1File = await picturesFolder.GetFileAsync(fileName); bmp.SetSource(await image1File.OpenAsync(FileAccessMode.Read));
- Marked as answer by ComiscienceHelloWorld Friday, April 6, 2012 11:02 AM
Friday, April 6, 2012 10:08 AM