Devexpress.Mvvm Winform

  1. 开始简单Text和ClickMe命令绑定
    
    namespace DXDemo
    {
        partial class MainView
        {
            /// <summary>
            /// Required designer variable.
            /// </summary>
            private System.ComponentModel.IContainer components = null;
    
            /// <summary>
            /// Clean up any resources being used.
            /// </summary>
            /// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
            protected override void Dispose(bool disposing)
            {
                if (disposing && (components != null))
                {
                    components.Dispose();
                }
                base.Dispose(disposing);
            }
    
            #region Windows Form Designer generated code
    
            /// <summary>
            /// Required method for Designer support - do not modify
            /// the contents of this method with the code editor.
            /// </summary>
            private void InitializeComponent()
            {
                this.components = new System.ComponentModel.Container();
                this.mvvmContext1 = new DevExpress.Utils.MVVM.MVVMContext(this.components);
                this.labelControl1 = new DevExpress.XtraEditors.LabelControl();
                this.btnChange = new DevExpress.XtraEditors.SimpleButton();
                ((System.ComponentModel.ISupportInitialize)(this.mvvmContext1)).BeginInit();
                this.SuspendLayout();
                // 
                // mvvmContext1
                // 
                this.mvvmContext1.ContainerControl = this;
                this.mvvmContext1.ViewModelType = typeof(DXDemo.MainViewModel);
                // 
                // labelControl1
                // 
                this.labelControl1.LineVisible = true;
                this.labelControl1.Location = new System.Drawing.Point(47, 30);
                this.labelControl1.Name = "labelControl1";
                this.labelControl1.Size = new System.Drawing.Size(71, 14);
                this.labelControl1.TabIndex = 0;
                this.labelControl1.Text = "This is a label";
                // 
                // btnChange
                // 
                this.btnChange.Location = new System.Drawing.Point(47, 78);
                this.btnChange.Name = "btnChange";
                this.btnChange.Size = new System.Drawing.Size(111, 24);
                this.btnChange.TabIndex = 1;
                this.btnChange.Text = "Change";
                // 
                // MainView
                // 
                this.AutoScaleDimensions = new System.Drawing.SizeF(7F, 14F);
                this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
                this.ClientSize = new System.Drawing.Size(1022, 736);
                this.Controls.Add(this.btnChange);
                this.Controls.Add(this.labelControl1);
                this.Name = "MainView";
                this.Text = "MainView";
                ((System.ComponentModel.ISupportInitialize)(this.mvvmContext1)).EndInit();
                this.ResumeLayout(false);
                this.PerformLayout();
    
            }
    
            #endregion
    
            private DevExpress.Utils.MVVM.MVVMContext mvvmContext1;
            private DevExpress.XtraEditors.SimpleButton btnChange;
            private DevExpress.XtraEditors.LabelControl labelControl1;
        }
    }
    
    
    using DevExpress.Mvvm.DataAnnotations;
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Data;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using System.Windows.Forms;
    
    namespace DXDemo
    {
        public partial class MainView : DevExpress.XtraEditors.XtraForm
        {
            public MainView()
            {
                InitializeComponent();
                if (!mvvmContext1.IsDesignMode)
                    InitializeBindings();
            }
    
            void InitializeBindings()
            {
                var fluent = mvvmContext1.OfType<MainViewModel>();
                fluent.SetBinding(labelControl1, l => l.Text, x => x.LabelText);
                fluent.BindCommand(btnChange,x=>x.ClickMe);
            }
        }
    
    
    }
    
    using DevExpress.Mvvm.DataAnnotations;
    
    namespace DXDemo
    {
        [POCOViewModel()]
        public class MainViewModel
        {
            public MainViewModel() {
                LabelText = "This Is Title";
            }
            public virtual string LabelText { get; set; }
    
            public void ClickMe() {
                LabelText = "Changed this Label";
            }
        }
    }
    

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值