大佬教程收集整理的这篇文章主要介绍了c# – 多个视图的相同命令,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
我的问题是:如何使用OOP原则编写通用代码而不破坏MVVM模式?我目前使用RelayCommand执行此操作的方法:
public RelayCommand ButtonCommand { get; private set; } #Constructor ButtonCommand = new RelayCommand(ExecuteButtonCommand,CanExecuteButtonCommand); #EndConstructor private void ExecuteButtonCommand(object messagE) { //Some method to fill the corresponding textfield } private bool CanExecuteButtonCommand(object messagE) { return true; }
绑定View1.xaml和View2.xaml中的按钮:
<Button Command="{Binding Path=ButtonCommand,Mode=OneWay}" />
这很糟糕,因为我必须为两个viewmodel编写相同的代码.我试图创建一个继承自RelayCommand的ButtonCommand类,但由于并非每个视图都具有此功能,因此我无法使用此方法实现它.
以上是大佬教程为你收集整理的c# – 多个视图的相同命令全部内容,希望文章能够帮你解决c# – 多个视图的相同命令所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。