C# ListBox不刷新ObservableCollection
我已经对这个问题做了一些研究,但找不到解决办法 问题是: 我有一个自定义类的可观察集合ListedNote。起初,列表框显示数据,但有些数据是异步加载的,不会更新。(例如,用户图片)C# ListBox不刷新ObservableCollection,c#,wpf,xaml,data-binding,listbox,C#,Wpf,Xaml,Data Binding,Listbox,我已经对这个问题做了一些研究,但找不到解决办法 问题是: 我有一个自定义类的可观察集合ListedNote。起初,列表框显示数据,但有些数据是异步加载的,不会更新。(例如,用户图片) 视图模型 .... private ObservableCollection<ListedNote> notes; public ObservableCollection<ListedNote> Notes { get { return note
视图模型
....
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;
}
});
}
。。。。
私人可观测收款票据;
公开募捐票据
{
获取{返回注释;}
设置{notes=value;RaisePropertyChanged(()=>this.notes);}
}
专用void LoadAttachmentsAsync(列出注释)
{
Async.Call(()=>this.ServiceConnector.RetrieveAnnounceAttachment(note.IdValue),
mm=>
{
如果(mm!=null)
{
if(mm.MultimediaType.iPicture)
注:附件图片=毫米;
其他的
注:附件文件=毫米;
note.AttachmentData=新列表(mm.数据);
var指数=此.Notes.IndexOf(注);
如果(索引>=0)
本条注释[索引]=注释;
}
});
}
有什么想法吗?
ObservableCollection
只会在集合的内容发生更改时通知用户界面:即,当添加或删除列表注释时。如果集合中已存在ListedNote
的属性更改,则它不会通知UI
您的ListedNote
类需要实现INotifyPropertyChanged
接口,以便UI知道某个单独便笺上的属性已更改。ObservableCollection
仅在集合的内容更改时通知UI:即,添加或删除列表注释时。如果集合中已存在ListedNote
的属性更改,则它不会通知UI
您的ListedNote
类需要实现INotifyPropertyChanged
接口,为了让UI知道个人备忘上的属性已更改。ObservableCollection是否会像在my viewModel中那样通知超额提交?ObservableCollection
只会在您的收藏内容更改时(即添加或删除项目时)发出通知。更改集合中项目的属性不会更改集合中的项目,因此ObservableCollection
对您没有帮助。您需要您的ListedNote
类在其属性更改时通知UI。ObservableCollection是否会像在my viewModel中那样通知overritings?ObservableCollection
仅在您的集合内容更改时(即添加或删除项目时)才会通知。更改集合中项目的属性不会更改集合中的项目,因此ObservableCollection
对您没有帮助。您需要您的ListedNote
类在其属性更改时通知UI。
....
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;
}
});
}