'List split into two - not updating Xamarin Forms

I have the below (simplified) model to display and return Chats. On the UI I want to show New Chats and Existing chats separately. When I first load the chats, it works, but if I update a Chat object, the UI doesn't update.

In the Xamarin Forms UI I have a 1) CollectionView binding to NewChats and 2) CollectionView binding to Existing Chats.

I update the IsNew flag programmatically, but that is not reflecting in the UI.

Any thoughts on how to approach this?

public class Chat 
{
    public string UserId {get;set;}
    public bool IsNew {get;set;}
}


private ObservableCollection<Chat> _chats;
public ObservableCollection<Chat> Chats
{
        get
        {
            return _chats;
        }

        set
        {
                this._chats= value;
                OnPropertyChanged(nameof(Chats));
                OnPropertyChanged(nameof(NewChats));
                OnPropertyChanged(nameof(ExistingChats));
        }
}


public ObservableCollection<Chat> NewChats
{
    get
    {
        if (_chats!= null)
        {
            return new ObservableCollection<Chat>(_chats.Where(x => x.isNew);
        }
               
        return new ObservableCollection<Chat>();
              
    }

}


public ObservableCollection<Chat> ExistingChats
{
    get
    {
        if (_chat!= null)
        {
            return new ObservableCollection<Chat>(_chats.Where(x => !x.isNew);
        }
        return new ObservableCollection<Chat>();
    }
}



Solution 1:[1]

As the comment above says For change notification to occur in a binding between a bound client and a data source, your bound type should either:

  • Implement the INotifyPropertyChanged interface (preferred).

  • Provide a change event for each property of the bound type.

you can check here to get offical sample:https://docs.microsoft.com/en-us/dotnet/api/system.componentmodel.inotifypropertychanged?view=net-6.0#definition

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Adrain Zhu -MSFT