带有 ObservableRangeCollection 的 CollectionView 不更新数据更改

CollectionView with ObservableRangeCollection not updating data change

我想更改我的 ObservableRangeCollection 中一个对象的数据,这可行,但相应的“CollectionView”不会更新更改后的数据。

'CollectionView`

<RefreshView Grid.Row="1"
                         Grid.RowSpan="2"
                         Command="{Binding RefreshCommand}"
                         IsRefreshing="{Binding IsBusy, Mode=OneWay}">

            <CollectionView x:Name="Collection"
                                ItemsSource="{Binding Locations}"
                                SelectionMode="Single"  
                                BackgroundColor="Transparent"
                                ItemsLayout="VerticalList">
                <CollectionView.EmptyView>
                    <StackLayout Padding="12">
                        <Label HorizontalOptions="Center" Text="Keine Daten vorhanden!" TextColor="White"/>
                    </StackLayout>
                </CollectionView.EmptyView>
                <CollectionView.ItemTemplate>
                    <DataTemplate x:DataType="models:MainModel">
                        <Frame HeightRequest="260">
                            <Grid>
                                <Image Source="{Binding Image}"
                                      Aspect="AspectFill"/>
                                <Label Text="{Binding Name}"
                                          FontSize="30"
                                       TextColor="White"/>

                            </Grid>
                        </Frame>
                    </DataTemplate>
                </CollectionView.ItemTemplate>
            </CollectionView>
        </RefreshView>

ViewModel

public class MainViewModel : VeiwModelBase
    {
        public ObservableRangeCollection<MainModel> Locations { get; set; } = new ObservableRangeCollection<MainModel>();

        public ICommand RefreshCommand { get; }

        public MainViewModel()
        {
            RefreshCommand = new AsyncCommand(Refresh);
        }

        public override void VModelActive(Page sender, EventArgs eventArgs)
        {
            base.VModelActive(sender, eventArgs);
            var locs = new MainModel() { Image = "https://club-l1.de/wp-content/uploads/2019/11/dsc08645-1200x800.jpg", Name = "Test" };
            Locations.Add(locs);

            foreach (MainModel loc in Locations)
            {
                loc.Name = "Update";
            }
        }

        private async Task Refresh()
        {
            IsBusy = true;


            var locs = new MainModel() { Image = "https://club-l1.de/wp-content/uploads/2019/11/dsc08645-1200x800.jpg", Name = "Test"};
            Locations.Add(locs);

            foreach (MainModel loc in Locations)
            {
                loc.Name = "Update";
            }

            IsBusy = false;
        }
    }

项目:https://github.com/Crey443/CollectionViewUpdate

MainModel需要实现INotifyPropertyChanged,任何你想绑定的属性(即Name)都需要在它们的setter[=15=中调用PropertyChanged ]

public class MainModel
{
    public string Name { get; set; }
    public string Image { get; set; }
}