ObservableCollection only provided notifications when we make any change in the collection itself like Adding or Removing an Item.
If we update any properties of a contained class, it doesn’t raise any notifications.
For e.g.
If I have an ObservableCollection of Person object and it is bind to a TreeView. If I add or remove person object from the ObservableCollection I will be able to see the changes in my TreeView also.
Here Person object has only one string property FullName
Now if I click on Change Name button, which simply renames the selected Person, I will not be able to see the change in my TreeView.
Here in this case we need to call the Refresh method of CollectionViewSource.
CollectionViewSource.GetDefaultView(this.observableCollPerson).Refresh();
https://skydrive.live.com/redir.aspx?cid=2312e1103cbe5ecd&resid=2312E1103CBE5ECD!339&parid=root
Have a look at this solution as well
Hope it helps.
Thanks! I had exactly the same problem and with your help I could solve it 😉
LikeLiked by 1 person
Thank you very much
LikeLiked by 1 person
Thanks!
LikeLiked by 1 person
thank you so much for sharing this !
LikeLiked by 1 person
Thanks, you saved my time!
LikeLiked by 1 person
I extended the ObservableCollection type
on your ViewModel you can call;
MyObservableCollection.SendUIRefreshNotification() – To Update all entries in the collection or;
MyObservableCollection.SendUIRefreshNotification(item) – To only refresh a specific entry
public static class FwExtensions
{
public static void SendUIRefreshNotification(this ObservableCollection observableCollection, T item)
{
var index = observableCollection.IndexOf(item);
observableCollection.Remove(item);
observableCollection.Insert(index, item);
}
public static void SendUIRefreshNotification(this ObservableCollection observablecollection)
{
var a = observablecollection.ToList();
foreach (var item in a)
{
observablecollection.SendUIRefreshNotification(item);
}
}
}
LikeLike
I’ve been trying to find a solution for the last 2 days. I have finally found your suggestion. Many thanks for sharing 🙂
LikeLike
CollectionViewSource.GetDefaultView(this.observableCollPerson).Refresh(); does not work in UWP project. Any Alternative ?
LikeLike
you saved me , thank you
LikeLiked by 1 person
Awesome 👍
LikeLike
Thanks, I was looking for the same
LikeLike
Thanks for the comment 👍
LikeLike
I will know, many thanks for the help in this question.
LikeLike