'Shell CollectionView is not updating Xamarin Forms

I'm trying to make CollectionView in Shell but it's not updating. I have one view model connected to Page and AppShell but when I update Collection view only page is updationg.

`public class AppShellViewModel : INotifyPropertyChanged
{
    public Command Load { get; }

    public ObservableCollection<ListData> _lists { get; set; }
    public ObservableCollection<ListData> Lists 
    {   
        get { return _lists; }
        set
        { 
            _lists = value;
            OnPropertyChanged();
        }
    }




    public AppShellViewModel()
    {

        Lists = new ObservableCollection<ListData>()
        {
            new ListData(){id=0,name="test",UserId=0},
            new ListData(){id=1,name="test1",UserId=1},
            new ListData(){id=2,name="test2",UserId=2},
            new ListData(){id=3,name="test3",UserId=3},
            new ListData(){id=4,name="test4",UserId=4}
        };
        Load = new Command(async () => await GetUserLists());
    }



    async Task GetUserLists()
    {
        for (int i = 5; i < 15; i++)
        {
            Lists.Add(new ListData {id=i, name=$"test{ i }", UserId=i });
        }
    }


    public event PropertyChangedEventHandler PropertyChanged;

    void OnPropertyChanged([CallerMemberName] string name = null)
    {
        PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
    }
}`

Then i have App Shell Collection View

`<Shell.FlyoutContent>
    <StackLayout BackgroundColor="#34495e">
        <Label Text="YOUR LISTS" FontSize="50" />
        <CollectionView ItemsSource="{Binding Lists}" >
            <CollectionView.ItemTemplate>
                <DataTemplate>
                    <StackLayout Padding="10" x:DataType="model:ListData">
                        <Label Text="{Binding name}" 
                            LineBreakMode="NoWrap"
                            FontSize="13" />
                    </StackLayout>
                </DataTemplate>
            </CollectionView.ItemTemplate>
        </CollectionView>
    </StackLayout>
</Shell.FlyoutContent>`

And There is Page CollectionView

`<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="ToDoApp.Views.AboutPage"
         xmlns:model="clr-namespace:ToDoApp.Models">
<StackLayout>
    <Button Text="Load" Command="{Binding Load}"/>
    <Label Text="{Binding error}"/>

    <CollectionView ItemsSource="{Binding Lists}">
        <CollectionView.ItemTemplate>
            <DataTemplate>
                <StackLayout Padding="10" x:DataType="model:ListData">
                    <Label Text="{Binding name}" 
                            LineBreakMode="NoWrap"
                            FontSize="13" />
                </StackLayout>
            </DataTemplate>
        </CollectionView.ItemTemplate>
    </CollectionView>
</StackLayout>
</ContentPage>`

before update it looks like this Page before update Shell before update

And after update the only what changed is content page and shell is the same as before Page after update Shell after update



Solution 1:[1]

Related to Jason's comment.

WON'T CHANGE TOGETHER

NOT the same instance - BindingContexts similar to these:

// In AppShell.xaml.cs.
public AppShell()
{
    InitializeComponent();
    BindingContext = new AppShellViewModel();
}

// In AboutPage.xaml.cs.
public AboutPage()
{
    InitializeComponent();
    BindingContext = new AppShellViewModel();
}

GOOD (SHARED BETWEEN TWO PLACES)

BindingContexts are SAME instance:

// In AppShellViewModel.cs.
public class AppShellViewModel ...
{
    private static AppShellViewModel _it;
    public static AppShellViewModel It
    {
        get {
            if (_it == null)
                _it = new AppShellViewModel();
            return _it;
        }
    }
}

// In AppShell.xaml.cs.
public AppShell()
{
    InitializeComponent();
    BindingContext = AppShellViewModel.It;
}

// In AboutPage.xaml.cs.
public AboutPage()
{
    InitializeComponent();
    BindingContext = AppShellViewModel.It;
}

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