Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/302.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# xamarin.forms:ListView未更新为Expexced_C#_Xamarin_Xamarin.forms - Fatal编程技术网

C# xamarin.forms:ListView未更新为Expexced

C# 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

我使用Xamarin.Forms构建了一个应用程序,我正在Windows中显示该应用程序。 要求: -点击列表视图中的项目> -项目的显示值将在UI中更改

下面是相关的xaml 注意:我已从代码隐藏中设置ListView.ItemsSource

  <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" >