我有這樣的Android設備上查看,這裏我使用LegacyBar:如何將一個命令的一個視圖中綁定到一個ViewModel在MvvmCross
public class BaseView : MvxActivity
{
public override void SetContentView(int layoutResId)
{
base.SetContentView(layoutResId);
var bar = FindViewById<LB.LegacyBar>(Resource.Id.actionbar);
bar.SetHomeLogo(Resource.Drawable.Icon);
var attr = this.GetType()
.GetCustomAttributes(typeof(ActivityAttribute), true)
.FirstOrDefault() as ActivityAttribute;
if (attr != null)
bar.Title = attr.Label;
bar.SetHomeAction(new ActionLegacyBarAction(ApplicationContext, doHomeAction, Resource.Drawable.Icon));
}
public ICommand homeActionClicked { get; set; }
private void doHomeAction()
{
if (homeActionClicked != null && homeActionClicked.CanExecute(null))
homeActionClicked.Execute(null);
}
}
什麼是綁定homeActionClicked
正道由此看來內部定義爲一個在其ViewModel命令? 或者,也許我應該做一個自定義控件,並把它放在裏面,然後綁定控件的命令?
什麼是'MvvMCore'? –
對不起,這是我的一個項目的代碼片段。這是我的MvvMCross項目(核心)的名稱空間,它與Android項目鏈接。如果將此代碼放置在活動的某個位置,則可以在視圖中訪問您的視圖模型。希望這有助於:) – Chris
謝謝。這或多或少是我認爲我會做的。我認爲,爲了我的應用程序的目的,我將採用Fluent方法。 –