我有这个 android View ,我在其中使用 LegacyBar:
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);
}
}
将此 View 中定义的 homeActionClicked
绑定(bind)到其 ViewModel 中的命令的正确方法是什么?
或者也许我应该制作一个自定义控件并将栏放在其中,然后绑定(bind)控件的命令?
最佳答案
您可以将 ViewModel 作为 View 中的属性进行引用,这样您就可以访问它的属性并设置从 View 到 View 模型的命令。
protected MvvMCore.Core.ViewModels.NavigationBarViewModel NavigationBarViewModel {
get{ return base.ViewModel as MvvMCore.Core.ViewModels.NavigationBarViewModel; }
}
关于c# - 如何将 View 内的命令绑定(bind)到 MvvmCross 中的 ViewModel,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19049786/