Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/xamarin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/heroku/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Xamarin MvvmCross 6 RecyclerView多按钮项目绑定_Xamarin_Android Recyclerview_Mvvmcross - Fatal编程技术网

Xamarin MvvmCross 6 RecyclerView多按钮项目绑定

Xamarin MvvmCross 6 RecyclerView多按钮项目绑定,xamarin,android-recyclerview,mvvmcross,Xamarin,Android Recyclerview,Mvvmcross,我对Xamarin真的很陌生&更多的是在MvvmCross。目前,我成功地做了一些基本的事情 但现在,我面临一个简单的问题(对我来说)。我得到了一个MvxRecyclerView。每个项目都有2个按钮。如何绑定它们?鉴于您的ViewModels: public class MyViewModel : MvxViewModel { public MyViewModel() { this.MyItems.Add(new MyItemViewModel());

我对Xamarin真的很陌生&更多的是在MvvmCross。目前,我成功地做了一些基本的事情

但现在,我面临一个简单的问题(对我来说)。我得到了一个
MvxRecyclerView
。每个项目都有2个按钮。如何绑定它们?

鉴于您的ViewModels:

public class MyViewModel : MvxViewModel
{
    public MyViewModel()
    {
        this.MyItems.Add(new MyItemViewModel());
        this.MyItems.Add(new MyItemViewModel());
    }

    public ObservableCollection<MyItemViewModel> MyItems { get; set; } = new ObservableCollection<MyItemViewModel>();
}

public class MyItemViewModel : MvxNotifyPropertyChanged
{
     public MyItemViewModel()
     {
          // Initialize your commands
     }

     public ICommand MyCommand1 { get; set; }

     public ICommand MyCommand2 { get; set; }
}

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <mvvmcross.droid.support.v7.recyclerview.MvxRecyclerView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scrollbars="vertical"
        local:MvxItemTemplate="@layout/item_test"
        local:MvxBind="ItemsSource MyItems" />
</LinearLayout>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:local="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="My button 1"
        local:MvxBind="Click MyCommand1" />
    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="My button 2"
        local:MvxBind="Click MyCommand2" />
</LinearLayout>