Refreshing ItemsControl Without Rebinding

Nathan Sokalski 4,111 Reputation points
2020-02-10T03:13:31.827+00:00

I have an ItemsControl inside a ScrollViewer. When an item in the ItemsControl changes, I need to rescroll to the same place, since I need to assing a new set of data to the ItemsSource. However, this frequent scrolling makes for a very ugly UI, so I am trying to figure out how to modify the current ItemsSource rather than assign it a new one. In my XAML, the ItemsSource is bound to a property that generates the IEnumerable, so I'm not sure if using an ObservableCollection would work. What should I do? Thanks.

Universal Windows Platform (UWP)
{count} votes

1 answer

Sort by: Most helpful
  1. Fay Wang - MSFT 5,221 Reputation points
    2020-02-10T06:38:11.903+00:00

    Hello,​

    ​Welcome to our Microsoft Q&A platform!

    When you change one or more properties which bind with control in ListViewItem, you just need to implement the INotifyPropertyChanged interface and PropertyChanged event to make your viewmodel observable. When the value of property changes, it will trigger the PropertyChanged event and notify the UI bound with the property to update. In that case, you don't have to use ObservableCollection.

    In addition, if you will remove or add items, it's better to use ObservableCollection as itemsSource. Since it implements the INotifyPropertyChanged and INotifyCollectionChanged interfaces, when remove or add items, these interfaces provide change notification to bindings.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.