0

我有一个带有标题和描述的图像列表(ListBox)。图像尚未下载,但标题和描述将首先显示。下载图像后,我怎么知道要更新图像?

部分xml:

<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>
4

2 回答 2

0

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

于 2013-01-25T07:07:30.310 回答
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,会引发属性更改通知,更新绑定。

于 2013-01-25T07:17:06.920 回答