にMvxRecyclerView項目の行動をアップ配線方法を私持って、次のAXMLファイルがあるMvxRecyclerView:のViewModel
<?xml version="1.0" encoding="utf-8"?>
<MvvmCross.Droid.Support.V7.RecyclerView.MvxRecyclerView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:MvxItemTemplate="@layout/item_detail"
app:MvxBind="ItemsSource Items" />
Correspodning ViewModelには次のように定義されています。
public class ItemsViewModel : MvxViewModel
{
private ObservableCollection<Models.Item> _items;
public ObservableCollection<Models.Item> Items
{
get { return _items; }
set
{
_items = value;
RaisePropertyChanged(() => Items);
}
}
public MvxCommand CommandToBeInvokedFromItem
{
get
{
return new MvxCommand(async() =>
{
await ...;
});
}
}
...
}
マイitem_detail AXMLは以下のように定義されているがこれは:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textSize="24dp"
local:MvxBind="Text Name" />
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/ic_delete_forever_black_24dp"
local:MvxBind="Click CommandToBeInvokedFromItem"/>
</LinearLayout>
Model.Itemは次のように定義されています。
public class Item
{
public string Name { get; set; }
}
最初にTextViewが機能するItemのnameプロパティにバインドされます。しかし、ImageButtonは、ItemのプロパティではなくMvxRecylerViewがバインドされているViewModelのCommandにバインドする必要があります。 Itemは単なるModelであり、ViewModelではありません。私はそれをどのように達成するのですか?
ルーク、ありがとうございますが、それは私が望む2番目の動作です。 MvxRecyclerViewの "セル"内にあるImageButtonのクリックにコマンドを接続したいと思います。そして、はい、私はMvxViewModelから継承するItemを持たないと、それを実行できるかどうか疑問に思っていました。 – Igor
'MvxViewModel'を継承せずに正常に動作するはずです。 'CommandToBeInvokedFromItem'を' Item'に移動するだけです。 –