tags:

views:

387

answers:

2

I need to refresh my ListView everytime the another control's IsChanged event is fired. I googled on how to do that, and I saw a stackoverflow link that led me here

One of the answers worked:

listView.ItemsSource = listView.ItemsSource

Is that really the only way to refresh my listview? It feels kinda off.

+1  A: 

Just invalidate it.

listView.InvalidateProperty(ListView.ItemsSourceProperty)

That ought to 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 would be my ViewModel I'm binding to:

public ObservableCollection<MyItem> MyItems
{
     get; set;
}

public void IsChangedHandler(...)
{
     ...
     this.OnPropertyChanged("MyItems");
}
Anderson Imes
A: 

What is your need to refresh the listview each time. It will definitly slow down the performance of your appliction.

It is better to use an ObervableCollection as your listview's ItemSource.

You can find a Thread safe observable collection here.

Also see this question in MSDN Forum - ListView.ItemsSource: howto update the UI whenever the source is updated?

Sauron