C# INotifyPropertyChanged列表视图

C# INotifyPropertyChanged列表视图,c#,listview,xamarin.forms,cross-platform,C#,Listview,Xamarin.forms,Cross Platform,我不熟悉Xamarin表单,并尝试在我的应用程序中实现无限循环功能。我遵循的示例代码运行良好,我已成功地将其集成到我的应用程序中 问题是我无法找到如何从代码中更改listview的源代码 我打算在我的listview上面有按钮(如下图所示),点击后listview的来源应该会改变 这就是我的代码的样子 <ContentPage.BindingContext> <local:MainViewModel /> </ContentPage.BindingCon

我不熟悉Xamarin表单,并尝试在我的应用程序中实现无限循环功能。我遵循的示例代码运行良好,我已成功地将其集成到我的应用程序中

问题是我无法找到如何从代码中更改listview的源代码

我打算在我的listview上面有按钮(如下图所示),点击后listview的来源应该会改变

这就是我的代码的样子

 <ContentPage.BindingContext>
    <local:MainViewModel />
</ContentPage.BindingContext>

<StackLayout>

    <ListView  x:Name="tyres_listview" ItemsSource="{Binding Items}"
                       HasUnevenRows="True" SeparatorVisibility="None"  >

        <ListView.Behaviors>
            <extended:InfiniteScrollBehavior IsLoadingMore="{Binding IsBusy}" />
        </ListView.Behaviors>
        <ListView.ItemTemplate>

            <DataTemplate>
                <ViewCell>

                    <StackLayout>
                        <Grid Margin="10" VerticalOptions="FillAndExpand" HorizontalOptions="FillAndExpand">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="0.25*"></ColumnDefinition>

                                <ColumnDefinition Width="0.75*"></ColumnDefinition>
                            </Grid.ColumnDefinitions>

                            <StackLayout  Grid.Column="0" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" Margin="5,5,5,10">
                                <Image  Source="{Binding image_url}"  >
                                </Image>
                            </StackLayout>
                            <StackLayout Grid.Column="1" Spacing="0" >
                                <Label Text="{Binding name}" FontAttributes="Bold" FontSize="Small" Margin="0,5,5,0" VerticalOptions="Center" ></Label>
                                <Label  Text="{Binding brand}" VerticalOptions="Center" FontSize="Micro"  ></Label>
                                <Label  Text="{Binding item_id}" VerticalOptions="Center" FontSize="Micro"  ></Label>

                                <StackLayout Orientation="Horizontal" x:Name="sl_db" >
                                    <Image Source="fuel.png" ></Image>
                                    <Label Text="{Binding fuel_type}"></Label>
                                    <Image Source="weather.png"></Image>
                                    <Label Text="{Binding wheather_type }"></Label>
                                    <Image Source="volume.png"  ></Image>
                                    <Label Text="{Binding noise}"></Label>
                                    <Label Text="dB"></Label>
                                </StackLayout>


                                <StackLayout Orientation="Horizontal">
                                    <Image></Image>
                                    <Label Text="{Binding rated_count }"></Label>
                                </StackLayout>

                                <StackLayout Orientation="Horizontal">
                                    <Label Text="Price: " VerticalOptions="Center"></Label>
                                    <Label Text="{Binding price }" VerticalOptions="Center" TextColor="Green"></Label>
                                    <Label Text=" EUR" VerticalOptions="Center"></Label>

                                </StackLayout>
                                <StackLayout Orientation="Horizontal">
                                    <StackLayout.GestureRecognizers>
                                        <TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped_1" >

                                        </TapGestureRecognizer>
                                    </StackLayout.GestureRecognizers>
                                    <StackLayout BackgroundColor="Red" Orientation="Horizontal" Margin="5" >
                                        <Image Source="shoppingcart.png" Margin="10,0,0,0"></Image>
                                        <Label Text="Add to Cart" VerticalOptions="Center" HorizontalOptions="EndAndExpand" Margin="0,0,10,0" ></Label>
                                    </StackLayout>
                                    <Image x:Name="button_info"  Source="info.png" >

                                        <Image.GestureRecognizers>
                                            <TapGestureRecognizer Tapped="button_info_Clicked"></TapGestureRecognizer>
                                        </Image.GestureRecognizers>

                                    </Image>
                                </StackLayout>

                            </StackLayout>

                        </Grid>
                    </StackLayout>

                </ViewCell>

            </DataTemplate>

        </ListView.ItemTemplate>

        <ListView.Footer>
            <Grid Padding="6" IsVisible="{Binding IsBusy}">
                <!-- set the footer to have a zero height when invisible -->
                <Grid.Triggers>
                    <Trigger TargetType="Grid" Property="IsVisible" Value="False">
                        <Setter Property="HeightRequest" Value="0" />
                    </Trigger>
                </Grid.Triggers>
                <!-- the loading content -->
                <Label Text="Loading..." TextColor="DeepPink" FontSize="20" FontAttributes="Bold" VerticalOptions="Center" HorizontalOptions="Center" />
            </Grid>
        </ListView.Footer>
    </ListView>
    <Button Clicked="button_Change_Order_Clicked"></Button>
</StackLayout>

public类主视图模型:INotifyPropertyChanged
{
私人厕所很忙;
private const int PageSize=10;
只读数据服务_DataService=new DataService();
公共无限滚动集合项{get;}
公共图书馆很忙
{
get=>\你很忙;
设置
{
_isBusy=值;
OnPropertyChanged();
}
}
公共主视图模型()
{
Items=新的InfiniteSrollCollection
{
OnLoadMore=async()=>
{
IsBusy=true;
//加载下一页
var page=项目数/页面大小;
var items=wait_dataService.GetItemsAsync(page,PageSize);
IsBusy=false;
//返回需要添加的项目
退货项目;
},
OnCanLoadMore=()=>
{
归还物品。计数<44;
}
};
下载DataAsync();
}
私有异步任务下载DataAsync()
{
var items=wait_dataService.GetItemsAsync(pageIndex:0,pageSize:pageSize);
Items.AddRange(Items);
}
公共事件属性更改事件处理程序属性更改;
受保护的虚拟void OnPropertyChanged([CallerMemberName]字符串propertyName=null)
{
PropertyChanged?.Invoke(这是新的PropertyChangedEventArgs(propertyName));
}
}
}


任何帮助都非常重要。

您的
列表视图。Items
属性已绑定到您的
MainViewModel。Items
属性,需要触发
PropertyChanged
事件来表示属性值的更改(如果
InfiniteSrollCollection
是可观察的集合,则对应于属性本身或其内容)

当您想要替换
源时,您可以给它一个新值,表示它已更改,并且您的
列表视图
可能会被刷新:

private InfiniteScrollCollection<Product_Search> _items;
public InfiniteScrollCollection<Product_Search> Items 
{ 
    get { return _items; }
    set
    {
        _items = value;
        OnPropertyChanged();
    }
}
private InfiniteScrollCollection\u项目;
公共集合项
{ 
获取{return\u items;}
设置
{
_项目=价值;
OnPropertyChanged();
}
}

在我设置轮胎的情况下,只需为轮胎分配另一个IEnumerable\u listview.ItemSourceif(轮胎\u listview.itemsource=somelist),它不具备无限卷轴的功能,然后使用另一个无限卷轴集合实例。您的问题确实没有明确说明您要解决的问题。我试图详细说明。正如您在所附图像中看到的,我有三个按钮。我希望单击按钮时更改listview的源。打开按钮Clck方法如果我设置listview.itemsource=somelist,它会更改列表视图,但它没有无限循环的功能。我正在寻找一种解决方案,在重新分配listview源时,我可以在MainViewModel中更改它,您是使用InfiniteSrollCollection还是其他类型?
private InfiniteScrollCollection<Product_Search> _items;
public InfiniteScrollCollection<Product_Search> Items 
{ 
    get { return _items; }
    set
    {
        _items = value;
        OnPropertyChanged();
    }
}