2013-01-25 45 views
0

我有一个图像列表(列表框)与标题和说明堆积。该图像尚未下载,但标题和说明将首先显示。下载图像时,如何告诉更新图像?动态绑定更新图像

部分XAML:

<ListBox.ItemTemplate> 
    <DataTemplate> 
     <Grid> 
      <Grid.ColumnDefinitions> 
       <ColumnDefinition Width="100" /> 
       <ColumnDefinition Width="*" /> 
      </Grid.ColumnDefinitions> 
      <Image Margin="5" Source="{Binding Image}" Grid.Column="0" Name="DCIM" /> 
      <TextBlock Grid.Column="1" Margin="2" Text="{Binding Title}" Name="Title" TextWrapping="NoWrap" TextTrimming="WordEllipsis" /> 
      <TextBlock Grid.Column="1" Margin="2" Text="{Binding Desc}" Name="count" TextWrapping="NoWrap" TextTrimming="WordEllipsis" /> 
     </Grid> 
    </DataTemplate> 
</ListBox.ItemTemplate> 

回答

0

您需要在您的项目类中实现INotifyPropertyChanged

public class MyDataItem : INotifyPropertyChanged 
{ 
    public event PropertyChangedEventHandler PropertyChanged; 

    private ImageSource image; 
    public ImageSource Image 
    { 
     get { return image; } 
     set 
     { 
      image = value; 
      NotifyPropertyChanged("Image"); 
     } 
    } 

    // do the same for Title and Desc 

    private void NotifyPropertyChanged(string propertyName) 
    { 
     if (PropertyChanged != null) 
     { 
      PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); 
     } 
    } 
} 

Image属性分配给,更新绑定的属性更改通知被引发。

+0

简单明了。这正是我需要的,谢谢:) – user1510539

0

当图像被下载调用NotifyProperyChanged("Image")更新Source="{Binding Image}"