我在FundamentalView.axml
<FrameLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingBottom="22dp"
android:paddingRight="22dp"
android:layout_alignParentBottom="true"
android:layout_alignParentEnd="true">
<ImageButton
android:id="@+id/addButton"
android:layout_width="56dp"
android:layout_height="56dp"
android:src="@drawable/ic_add_white_24dp" />
</FrameLayout>
在 FundamentalView.cs 中,我有一个click事件,它从视图底部触发一个片段,并带有选项(添加一个新人和新计算)。
var addButton = view.FindViewById<ImageButton>(Resource.Id.addButton);
addButton.Click += OnAddButtonClick;
void OnAddButtonClick(object sender, System.EventArgs e)
{
var dialog = new CardDialogView();
dialog.Show(((MainView)Activity).SupportFragmentManager, "CardDialogView");
}
CardDialogView.axml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#FFFFFF">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/dash_add_computer"
android:textColor="@color/primary_text"
android:textSize="16sp"
android:text="New Calculation"
local:MvxBind="Click NewCalculationCommand"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/dash_add_head"
android:drawablePadding="28dp"
android:textColor="@color/primary_text"
android:textSize="16sp"
android:text="New Person" />
</LinearLayout>
我的问题是如何使TextView可以点击并知道在mvvmcross中点击了哪个textview?
CardDialogView.cs
public class CardDialogView : MvxDialogFragment<CardDialogViewModel>
{
public override Dialog OnCreateDialog(Bundle savedState)
{
.....
return dialog;
}
}
CardDialogViewModel.cs
public class CardDialogViewModel : MvxViewModel
{
public ICommand NewCalculationCommand
{
get
{
// it does not come here!
return new MvxCommand(() => ShowViewModel<NewItemViewModel>(new { date = DateTime.Now }));
}
}
}
答案 0 :(得分:3)
您可以像单击按钮一样绑定textview click:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="@drawable/dash_add_computer"
android:textColor="@color/primary_text"
android:textSize="16sp"
local:MvxBind="Click NewCalculationCommand"
android:text="New Calculation" />
对于第二个textview,将其绑定到另一个命令。这样,当调用相应的命令时,您将知道哪个textview触发了它。