Hello! I am interested in this question: I have a collection of pictures asynchronously downloaded and attached to the wpf page, but during the download, when the value of each element of the pictures is null, I have empty space. How to upload a default image to this empty place? I tried the TargetNullValue parameter but there is no result.
A snippet of WPF code:
<ItemsControl Grid.Row="0" ItemsSource="{Binding RecentMedias}" > <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <UniformGrid Columns="5" Rows="6" /> </ItemsPanelTemplate> </ItemsControl.ItemsPanel> <ItemsControl.ItemTemplate> <DataTemplate> <Image Source="{Binding Path=Images, IsAsync=True, TargetNullValue=DefaultImage}"/> </Image> </DataTemplate> </ItemsControl.ItemTemplate> </ItemsControl> Scrap C #:
private ImageSource defaultImage = null; public ImageSource DefaultImage { get { return defaultImage; } set { defaultImage = value; NotifyPropertyChanged("DefaultImage"); } } public class SelectedMedia : INotifyPropertyChanged { private ImageSource images = null; public ImageSource Images { get { return images; } set { images = value; NotifyPropertyChanged("Images"); } } public virtual event PropertyChangedEventHandler PropertyChanged; protected virtual void NotifyPropertyChanged(params string[] propertyNames) { if (PropertyChanged != null) { foreach (string propertyName in propertyNames) PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); PropertyChanged(this, new PropertyChangedEventArgs("HasError")); } }