-
Notifications
You must be signed in to change notification settings - Fork 3
/
PropertyChangedNotificationsUserControl.cs
82 lines (76 loc) · 3.51 KB
/
PropertyChangedNotificationsUserControl.cs
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
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
using DevExpress.Mvvm;
using DevExpress.Mvvm.DataAnnotations;
using DevExpress.Mvvm.POCO;
using DevExpress.Utils.MVVM;
using DevExpress.XtraEditors;
using System;
using System.Windows.Forms;
namespace DxSamplePOCODependencies {
public partial class PropertyChangedNotificationsUserControl : XtraUserControl {
public PropertyChangedNotificationsUserControl() {
InitializeComponent();
#region SetUp
MVVMContext mvvmContext = new MVVMContext();
mvvmContext.ContainerControl = this;
TextEdit editor1 = new TextEdit();
editor1.Dock = DockStyle.Top;
editor1.Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.Numeric;
editor1.Properties.Mask.EditMask = "n0";
editor1.Properties.Mask.UseMaskAsDisplayFormat = true;
TextEdit editor2 = new TextEdit();
editor2.Dock = DockStyle.Top;
editor2.Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.Numeric;
editor2.Properties.Mask.EditMask = "n0";
editor2.Properties.Mask.UseMaskAsDisplayFormat = true;
LabelControl resultLabel = new LabelControl();
resultLabel.Dock = DockStyle.Top;
resultLabel.AutoSizeMode = LabelAutoSizeMode.Vertical;
resultLabel.Parent = this;
editor1.Parent = this;
editor2.Parent = this;
#endregion SetUp
#region #propertyChangedNotifications
// Set type of POCO-ViewModel
mvvmContext.ViewModelType = typeof(SumViewModel);
// Data binding for the operands
mvvmContext.SetBinding(editor1, e => e.EditValue, "Operand1");
mvvmContext.SetBinding(editor2, e => e.EditValue, "Operand2");
// Data binding for the result
mvvmContext.SetBinding(resultLabel, l => l.Text, "ResultText");
#endregion #propertyChangedNotifications
}
#region CleanUp
void OnDisposing() {
var context = MVVMContext.FromControl(this);
if(context != null) context.Dispose();
}
#endregion CleanUp
//
// POCO View Model supports attributes and extension-methods for different purposes.
//
public class SumViewModel {
public SumViewModel() {
Operand1 = 2;
Operand2 = 2;
}
// using the BindableProperty attribute
[BindableProperty(OnPropertyChangedMethodName = "NotifyResultAndResultTextChanged")]
public virtual int Operand1 { get; set; }
// using the BindableProperty attribute
[BindableProperty(OnPropertyChangedMethodName = "NotifyResultAndResultTextChanged")]
public virtual int Operand2 { get; set; }
// We will raise change-notification for this property manually
public int Result {
get { return Operand1 + Operand2; }
}
// We will raise change-notification for this property manually
public string ResultText {
get { return string.Format("The result of operands summarization is: {0:n0}", Result); }
}
protected void NotifyResultAndResultTextChanged() {
this.RaisePropertyChanged(x => x.Result); // change-notification for the Result
this.RaisePropertyChanged(x => x.ResultText); // change-notification for the ResultText
}
}
}
}