C # UWP Windows 10 project

The model has a collection of objects:

private ObservableCollection<GroupInfoList> _groupedTransactions = null; public ObservableCollection<GroupInfoList> groupedTransactions { get { if (_groupedTransactions == null) { _groupedTransactions = DBManager.getGroupedTransactions(); } return _groupedTransactions; } set { _groupedTransactions = value; } } 

When I add \ change \ delete items one by one, everything is ok, the changes are immediately displayed in the ListView , but when I need to completely update the collection:

 private async void Signals_NeedRefreshTransEvent() { await Task.Run(() => { groupedTransactions = DBManager.getGroupedTransactions(); }); } 

That ListView does not change, and will stop responding to future changes. How to make it update the UI without updating the source in the form code?

    1 answer 1

    I see two options:

    1. In the set collection, call the implementation INotifyPropertyChanged

    2. set to make private, instead of perebivka use Clear and AddRange (which by default is not, you have to write separately).

    The first option is more obvious and easier.

    • Thanks for the answer, I have already tried it all myself)) 1) not an option, because it does not work (most likely the link to the collection is lost during the assignment and the only option is to overload it). 2) It works, I call Clear , and then foreach and add - not the best solution, of course, but for now it will do. In the future, I will rewrite the MB for comparing each element and updating / inserting if necessary (although not the fact that it will be better) - SYL
    • @SYL if the groupedTransactions property groupedTransactions bound on ItemsSource on the ListView , then the first option should work. - Monk
    • I also thought so, but it does not work - SYL