2012-08-06 69 views
0

我已经对这个问题做了一些研究,但是我找不到解决方法。ListBox不刷新ObservableCollection

Here's问题:

我有我的自定义类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; 


        } 
       }); 
     } 

任何想法?

回答

4

ObservableCollection只会在集合内容发生变化时通知用户界面:即,当添加或删除ListedNote时。如果集合中已有ListedNote的属性发生更改,它将不会通知UI。

ListedNote您的ListedNote类需要实现INotifyPropertyChanged接口,以便UI知道某个属性在个别注释中发生了变化。

+0

ObservableCollection是否不会像我的viewModel中那样通知重载? – Cr3at0rX 2012-08-06 09:37:50

+1

ObservableCollection'只会在集合中的内容发生变化时才会通知 - 即,当您添加或删除某个项目时。更改集合中项目的属性*不会更改集合中的项目,因此“ObservableCollection”不会帮助您。当* its *属性更改时,您需要使用“ListedNote”类来通知UI。 – 2012-08-06 09:40:23