zoukankan      html  css  js  c++  java
  • Devexpress Winform 使用MVVM

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

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

    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 { get; set; }
                // 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的值。

  • 相关阅读:
    手把手教您玩转信用卡 如何“以卡养卡”合法“套现”
    267家已获第三方许可机构名单查询
    C#生成图片验证码
    File I/O
    文件上传代码
    集合框架
    接口
    多态
    封装
    jsp做成mvc模式的代码
  • 原文地址:https://www.cnblogs.com/zhaogaojian/p/5978236.html
Copyright © 2011-2022 走看看