Quantcast
Channel: WPF – Nishant Rana's Weblog
Viewing all articles
Browse latest Browse all 6

Refresh ObservableCollection in WPF

$
0
0

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

http://blog.falafel.com/blogs/11-01-30/Using_CollectionViewSource_without_Refresh_for_Faster_Filtering_in_Silverlight

Hope it helps.


Filed under: WPF Tagged: WPF

Viewing all articles
Browse latest Browse all 6

Trending Articles