Devexpress Winform 使用MVVM

Devexpress Winform 使用MVVM

zhaogaojian

MVVM在WPF里很早就有了,在Winform里Devexpress最近几个大版本才有的事,上一段代码。

现在对话框上添加三个控件simpleButton1,simpleButton2,textEdit1,MvvmContext组件

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

public partial class Form1 : DevExpress.XtraEditors.XtraForm

    {

        //

        // POCO View Model provides out-of-the-box support of the INotifyPropertyChanged.

        //

        public class ViewModel{

            // Bindable property will be created from this property.

            public virtual string Title { getset; }

            // Just a method for readability

            public string GetTitleAsHumanReadableString(){

                if (Title == null)

                    return "(Null)";

                if (Title.Length == 0)

                    return "(Empty)";

                if (string.IsNullOrWhiteSpace(Title))

                    return "(WhiteSpace)";

                return Title;

            }

        }

        public Form1(){

            InitializeComponent();

        }

 

        private void simpleButton1_Click(object sender, EventArgs e){

 

            // Set type of POCO-ViewModel

            mvvmContext1.ViewModelType = typeof(ViewModel);

            // Data binding for the Title property (via MVVMContext API)

            mvvmContext1.SetBinding(textEdit1, c=>c.EditValue, "Title");

            // UI binding for the Report command

            ViewModel viewModel = mvvmContext1.GetViewModel<ViewModel>();

            simpleButton2.Click += (s, ee) => XtraMessageBox.Show(viewModel.GetTitleAsHumanReadableString());

             

 

        }

当simpleButton1点击执行后,simpleButton2点击后显示的就是textEdit1的值。

1、建了一个小群:616945527(软件), 欢迎大家加入,加群口令abc123,硬件开发者推荐75764412(单片机)。
闲置域名www.nsxz.com出售(等宽等高字符四字域名,可组合多种有意义词语)。

分类: 第三方界面库

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值