2013-01-25 85 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}"