にリストビュー内の項目を削除します。RemoveItemメソッドが呼び出されるとビューは更新されません、アイテムが何のリストビューから削除されますこれは私のコードであるタップ
public partial class MyGS: ContentPage {
public MyGS() {
InitializeComponent();
BindingContext = new MyGSViewModel();
}
public class MyGSViewModel: INotifyCollectionChanged {
public event NotifyCollectionChangedEventHandler CollectionChanged;
public ObservableCollection <SchItem> Items {get;private set;}
public MyGSViewModel() {
Items = new ObservableCollection<SchItem>();
//Item Population
public void removeItem(int rid, int lid) {
SchItem myItem = Items[lid];
Items.Remove(myItem);
CollectionChanged ? .Invoke(this, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Remove, myItem));
}
}
public class SchItem {
public int realm_id {get;set;}
public int list_id {get;set;}
public ICommand TapCommand {
get {return new Command(() => {
Debug.WriteLine("COMMAND: " + list_id);
MyGSViewModel gsvm = new MyGSViewModel();
gsvm.removeItem(realm_id, list_id);
});
}
}
}
}
、多分問題がて、CollectionChangedについてですが、私はそれを修正する方法を取得しません。
注:Androidデバイスでのデバッグ
、私は 'System.In validCastException:指定されたキャストが無効です。 '多分私はアイテム定義クラスでタップコマンドを持っているので? 編集:私はSchISTemを戻しましたが、MyGSViewModelはCommandParameterとしてではありません。 – Segamoto
@Segamoto O right、 'BindingContext'はオブジェクトです。リストビューなのでオブジェクトです...その場合、私は間違いなく' Tapped'イベント。私は私の答えを編集します。 – hvaughan3
@Segamoto Check now – hvaughan3