Windowsで表示しているXamarin.Formsを使用してアプリケーションを構築しました。 要件: - > リストビュー内の項目をタップ - ここではUIxamarin.forms:リストビューがexpexctedとして更新されない
の項目の変更のために表示される値は、関連するXAML NOTEです:私は
<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.ItemsSourceを設定しています
ここでは、項目がタップされてもうまく動作するが、UIは変更されないC#コードの背後にあります。
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を実装していますか? – Jason