视频图像处理系列索引 || 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

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

ViewModel

1
2
3
4
5
6
7
8
9
10
11
12
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

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

ViewModel

1
2
3
4
5
6
7
8
9
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

1
2
3
4
5
6
7
8
9
10
<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

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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

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

  

ViewModel

1
2
3
4
5
6
7
8
9
public void GridControl_MouseDoubleClick(object sender, MouseButtonEventArgs e)
        {
            var row = (sender as GridControl).CurrentItem;
            if (!(row is CreateIncidentInfomationModel createIncidentInfoModel))
            {
                return;
            }
 
        }

  

posted @   jhlong  阅读(1226)  评论(0编辑  收藏  举报
编辑推荐:
· 10年+ .NET Coder 心语,封装的思维:从隐藏、稳定开始理解其本质意义
· .NET Core 中如何实现缓存的预热?
· 从 HTTP 原因短语缺失研究 HTTP/2 和 HTTP/3 的设计差异
· AI与.NET技术实操系列:向量存储与相似性搜索在 .NET 中的实现
· 基于Microsoft.Extensions.AI核心库实现RAG应用
阅读排行:
· 10年+ .NET Coder 心语 ── 封装的思维:从隐藏、稳定开始理解其本质意义
· 地球OL攻略 —— 某应届生求职总结
· 提示词工程——AI应用必不可少的技术
· Open-Sora 2.0 重磅开源!
· 周边上新:园子的第一款马克杯温暖上架
海龙的博客 jhlong@cnblogs 版权所有© 转载请注明链接.有用请推荐一下
代码全部经过本人测试,但不保证复制粘贴就正常运行,更不保证能解决你的问题,请结合前后代码及描述理解后修改和使用
点击右上角即可分享
微信分享提示