【发布时间】:2016-11-09 17:02:29
【问题描述】:
我已经使用我在 Windows 中显示的 Xamarin.Forms 构建了一个应用程序。 要求: - 点击列表视图中的项目 > - 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 >
这是后面的c#代码,当项目被点击时运行良好,但UI没有改变。
public ObservableCollection oc;
public void GroceryItemTapped (object o, ItemTappedEventArgs e )
{
if (e.Item == null ) {
return;
}
var g = ((GroceryItem)e.Item);
// oc is populated and exactly what I expect here
foreach (var gr in oc)
{
// the next line grabs the item I want
if (gr.GroceryId == g.GroceryId)
{
gr.GroceryName = "snot";
} } }
// when the above code runs, the data is already in oc and this code ran
lvGroceries.ItemsSource = oc;
想法?
【问题讨论】:
-
GroceryItem 是否实现了 INotifyPropertyChanged?
标签: c# xamarin xamarin.forms