Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/333.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# ListBox不刷新ObservableCollection_C#_Wpf_Xaml_Data Binding_Listbox - Fatal编程技术网

C# ListBox不刷新ObservableCollection

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

我已经对这个问题做了一些研究,但找不到解决办法

问题是:

我有一个自定义类的可观察集合ListedNote。起初,列表框显示数据,但有些数据是异步加载的,不会更新。(例如,用户图片)


视图模型

....
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;


                    }
                });
        }