如何使用子视图模型方法创建父视图绑定命令

时间:2018-01-11 10:04:34

标签: winforms mvvm devexpress

我在父视图中有一个simpleButton,我希望将此按钮与子视图模型中的方法绑定。

_fluentApi.BindCommand(simpleButton , x => x.SaveMessage());

1 个答案:

答案 0 :(得分:0)

DevExpress MVVM Fluent API支持绑定到嵌套属性/命令:

// ViewModel
public class ParentViewModel {
    public ParentViewModel() {
        Child = ChildViewModel.Create();
    }
    public virtual ChildViewModel Child { 
        get;
        protected set;
    }
}
public class ChildViewModel{
    public static ChildViewModel Create() {
        return DevExpress.Mvvm.POCO.ViewModelSource.Create<ChildViewModel>();
    }
    public void Save(){
        // ...
    }
}

// View
var fluentApi = mvvmContext.OfType<ParentViewModel>()
fluentApi.BindCommand(simpleButton , x => x.Child.Save());
相关问题