Xamarin MvvmCross 6 RecyclerView多按钮项目绑定
我对Xamarin真的很陌生&更多的是在MvvmCross。目前,我成功地做了一些基本的事情 但现在,我面临一个简单的问题(对我来说)。我得到了一个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());
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>