视频图像处理系列索引 || Arcgis/Engine/Server开发索引 || Web Map Gis开发索引 || jquery表格组件 JQGrid索引
WPF MVVM模式开发实现简明教程索引 || ArcGIS Runtime WPF(.net C#)开发简明教程索引

WPF MVVM模式开发简明实现教程 7 DevExpress MVVM

WPF MVVM模式开发实现简明教程 1 开篇简介 

WPF MVVM模式开发实现简明教程 2 初识 INotifyPropertyChanged

WPF MVVM模式开发简明实现教程 3 事件绑定   

WPF MVVM模式开发实现简明教程 3-1 BaseCommand  

WPF MVVM模式开发实现简明教程 4 ViewModelBase  

WPF MVVM模式开发简明实现教程 5 使用MultiValueConverter进行多参数事件绑定 

WPF MVVM模式开发简明实现教程 6 其他绑定  

WPF MVVM模式开发简明实现教程 7 DevExpress MVVM  

WPF MVVM模式开发简明实现教程 8 完结 附全部代码  

 

可以看到比原生的用法简单很多,POCO View 结合 DXCommand很方便

自己其实也可以实现

 

ViewModelBase

View

<Button Command="{Binding LoginCommand}">Login</Button>
        <TextBlock Text="{Binding Status}" />

ViewModel

public string Status {
            get { return GetValue<string>(); }
            private set { SetValue(value); }
        }

        [Command]
        public void Login() {
            Status = "User: " + UserName;
        }
        public bool CanLogin() {
            return !string.IsNullOrEmpty(UserName);
        }

 

POCO View

View

<Button Command="{Binding LoginCommand}">Login</Button>
        <TextBlock Text="{Binding Status}" />

ViewModel

        public virtual string Status { get; protected set; }

        // LoginCommand will be created for the Login and CanLogin methods: 
        public void Login() {
            Status = "User: " + UserName;
        }
        public bool CanLogin() {
            return !string.IsNullOrEmpty(UserName);
        }

  

DelegateCommand

view

<dxlc:LayoutControl Orientation="Vertical" VerticalAlignment="Top">
        <dxlc:LayoutGroup Header="Command without parameter" Orientation="Vertical" View="GroupBox">
            <CheckBox IsChecked="{Binding CanExecuteSaveCommand}" Content="Can Save"/>
            <Button Command="{Binding SaveCommand}">Save</Button>
        </dxlc:LayoutGroup>
        <dxlc:LayoutGroup Header="Command with parameter" Orientation="Vertical" View="GroupBox">
            <dxe:TextEdit Text="{Binding FileName, UpdateSourceTrigger=PropertyChanged}" NullText="Enter file name"/>
            <Button Command="{Binding OpenCommand}" CommandParameter="{Binding FileName}">Open</Button>
        </dxlc:LayoutGroup>
    </dxlc:LayoutControl>

ViewModel

public ICommand SaveCommand { get; private set; }
        public ICommand OpenCommand { get; private set; }

        public DelegateCommandsViewModel() {
            CanExecuteSaveCommand = true;

            SaveCommand = new DelegateCommand(
                () => MessageBox.Show("Action: Save"),
                () => CanExecuteSaveCommand);

            OpenCommand = new DelegateCommand<string>(
                fileName => MessageBox.Show(string.Format("Action: Open {0}", FileName)),
                fileName => !string.IsNullOrEmpty(fileName));
        } 

        public bool CanExecuteSaveCommand {
            get { return GetValue<bool>(); }
            set { SetValue(value); }
        }
        public string FileName {
            get { return GetValue<string>(); }
            set { SetValue(value); }
        }

  

DXCommand

View

<dxg:GridControl MouseDoubleClick="{DXEvent 'GridControl_MouseDoubleClick(@sender, @args)'}" >

  

ViewModel

public void GridControl_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var row = (sender as GridControl).CurrentItem;
            if (!(row is CreateIncidentInfomationModel createIncidentInfoModel))
            {
                return;
            }

        }

  

posted @ 2020-12-17 17:33  jhlong  阅读(1103)  评论(0编辑  收藏  举报
海龙的博客 jhlong@cnblogs 版权所有© 转载请注明链接.有用请推荐一下
代码全部经过本人测试,但不保证复制粘贴就正常运行,更不保证能解决你的问题,请结合前后代码及描述理解后修改和使用