- 开始简单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"; } } }
Devexpress.Mvvm Winform
最新推荐文章于 2024-07-28 23:23:55 发布