问题
I have a parent view model. Let's call it ParentViewModel. In ParentView.axml I have this MvxListView code:
<Mvx.MvxListView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:elevation="0dp"
android:padding="5dp"
local:MvxItemTemplate="@layout/childlistitem"
local:MvxBind="ItemsSource Items" />
So it is obvious that I have ChildListItemViewModel as well...
Now each Item has some parameters inside such as "Id, name,...." besides that my each Item has two buttons: "Edit" and "Delete". This looks like this:
For example I need to delete one Item. I don't know how to bind click event to the ParentViewModel instead of ChildListItemViewModel... How could I do that?
I tried to bind click to this kind of parameter that calls command from parent view model:
public IMvxCommand<ParentViewModel> Delete => new MvxCommand<ParentViewModel>(x =>
{
x.DeleteCommand.Execute(Id);
});
but x is always null, so I'm out of the thoughts....
In other words.. How can I bind parent view model command on child click?
来源:https://stackoverflow.com/questions/46686939/how-to-control-child-view-model-from-parent-view-model-in-xamarin-mvvmcross