【发布时间】:2012-08-03 06:27:13
【问题描述】:
我已经对该问题进行了一些研究,但找不到解决方法。
问题来了:
我有一个自定义类 ListedNote 的 observableCollection。起初 ListBox 显示数据,但有些数据是异步加载的,不会更新。 (例如用户图片)
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ListBox ItemsSource="{Binding Notes, UpdateSourceTrigger=PropertyChanged}" x:Name="Content" ItemTemplate="{StaticResource ListBoxCardFBLikeTemplate}"
HorizontalContentAlignment="Stretch">
</ListBox>
</ScrollViewer>
视图模型
....
private ObservableCollection<ListedNote> notes;
public ObservableCollection<ListedNote> Notes
{
get { return notes; }
set { notes = value; RaisePropertyChanged(() => this.Notes); }
}
private void LoadAttachmentsAsync(ListedNote note)
{
Async.Call(() => this.ServiceConnector.RetrieveAnnouncementAttachment(note.IdValue),
mm =>
{
if (mm != null)
{
if (mm.MultimediaType.IsPicture)
note.AttachedPicture = mm;
else
note.AttachedFile = mm;
note.AttachmentData = new List<byte>(mm.Data);
var index = this.Notes.IndexOf(note);
if (index >= 0)
this.Notes[index] = note;
}
});
}
有什么想法吗?
【问题讨论】:
标签: c# wpf xaml data-binding listbox