How to control child view model from parent view model in xamarin mvvmCross?

爱⌒轻易说出口 提交于 2019-12-24 12:14:42

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!