C# xamarin.forms:ListView未更新为Expexced
我使用Xamarin.Forms构建了一个应用程序,我正在Windows中显示该应用程序。 要求: -点击列表视图中的项目> -项目的显示值将在UI中更改 下面是相关的xaml 注意:我已从代码隐藏中设置ListView.ItemsSourceC# xamarin.forms:ListView未更新为Expexced,c#,xamarin,xamarin.forms,C#,Xamarin,Xamarin.forms,我使用Xamarin.Forms构建了一个应用程序,我正在Windows中显示该应用程序。 要求: -点击列表视图中的项目> -项目的显示值将在UI中更改 下面是相关的xaml 注意:我已从代码隐藏中设置ListView.ItemsSource <ListView.ItemTemplate > <StackLayout VerticalOptions="Center" HorizontalOptions="Center" > <Label Text
<ListView.ItemTemplate >
<StackLayout VerticalOptions="Center" HorizontalOptions="Center" >
<Label Text="Passo dopo passo" VerticalOptions="Center" HorizontalOptions="Center" />
<Button Clicked="GetGroceries" Text="Get Groceries" ></Button>
<ListView x:Name="lvGroceries" ItemTapped="GroceryItemTapped" >
<ListView.ItemTemplate >
想法?您需要将您的
列表视图
绑定到您的收藏:
<ListView x:Name="lvGroceries" ItemsSource="{Binding oc}" ItemTapped="GroceryItemTapped" >
您还需要设置ContentPage.BindingContext
。您还需要实现INotifyPropertyChanged
,并在更新集合时运行OnPropertyChanged()
。最后,您需要通过执行oc.add()
来添加到集合中,而不是每次都重置ItemSource
,因为这将覆盖您的绑定
强烈建议查看。杂货店项目是否实施INotifyPropertyChanged?感谢指导。我会试试的。当然,我一直在研究Xamarin博士。除非我试过,否则我在这里提问是不负责任的。我只需要做你提到的4件事中的一件,但是你得到了绿色的复选标记。我有一个类GroceryItem,我必须在该类中实现INotifyPropertyChanged,并为我正在更改的属性触发OnPropertyChanged事件。这个msdn文档真的帮助了我@Pdshuller很高兴它对您有所帮助,并感谢您为其他人添加链接!如果您遇到任何其他问题,请告诉我。感谢您在相关问题上提供帮助。我这里还有一个帖子
<ListView x:Name="lvGroceries" ItemsSource="{Binding oc}" ItemTapped="GroceryItemTapped" >