I´ve already done some research on that problem, but I can´t find a workaround.
Here´s the problem:
I have an observableCollection of my custom class ListedNote. At first the ListBox displays the data, but there are some datas which are loaded async and won´t be updated. (e.g. a user picture)
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ListBox ItemsSource="{Binding Notes, UpdateSourceTrigger=PropertyChanged}" x:Name="Content" ItemTemplate="{StaticResource ListBoxCardFBLikeTemplate}"
HorizontalContentAlignment="Stretch">
</ListBox>
</ScrollViewer>
The ViewModel
....
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;
}
});
}
Any idea?
ObservableCollectionwill only notify the UI when the collection’s contents have changed: that is, when aListedNoteis added or removed. It won’t notify the UI if the properties of aListedNotealready in the collection change.Your
ListedNoteclass needs to implement theINotifyPropertyChangedinterface, in order for the UI to know that a property has changed on an individial note.