More elegant ListView request

I need to update my ListView every time another IsChanged control event is IsChanged . I googled on how to do this and I saw a stackoverflow link that brought me here

One of the answers worked:

 listView.ItemsSource = listView.ItemsSource 

Is this really the only way to update my ListView ? He feels amiable.

+2
source share
2 answers

Just cancel it.

 listView.InvalidateProperty(ListView.ItemsSourceProperty) 

That should do it.

As an aside, I would really suggest looking at MVVM. It tends to be much more powerful. In this case, for an MVVM application, I would just do this:

Xaml:

 <ListView ItemsSource="{Binding MyItems}" /> 

And here is my ViewModel to which I am attached:

 public ObservableCollection<MyItem> MyItems { get; set; } public void IsChangedHandler(...) { ... this.OnPropertyChanged("MyItems"); } 
+5
source

What is your need to update the list every time. This will definitely slow down your application.

It is better to use ObervableCollection as an element of the ItemSource list.

You can find the stream protected collection here .

Also see this question in the MSDN forum - ListView.ItemsSource: how to update the user interface when updating the source?

+1
source

All Articles