-
Notifications
You must be signed in to change notification settings - Fork 2
/
DataBindingViaDefaultConvertersFluentAPIUserControl.vb
50 lines (45 loc) · 2.02 KB
/
DataBindingViaDefaultConvertersFluentAPIUserControl.vb
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
Imports DevExpress.Mvvm
Imports DevExpress.Mvvm.DataAnnotations
Imports DevExpress.Mvvm.POCO
Imports DevExpress.Utils.MVVM
Imports DevExpress.XtraEditors
Imports System
Imports System.Windows.Forms
Namespace DxSampleDataBindingCapabilitiesConverters
Partial Public Class DataBindingViaDefaultConvertersFluentAPIUserControl
Inherits DevExpress.XtraEditors.XtraUserControl
Public Sub New()
InitializeComponent()
Dim mvvmContext As New MVVMContext()
mvvmContext.ContainerControl = Me
Dim trackBar As New TrackBarControl()
trackBar.Dock = DockStyle.Top
trackBar.Properties.Minimum = 0
trackBar.Properties.Maximum = 100
Dim editor As New TextEdit()
editor.Dock = DockStyle.Top
editor.Properties.Mask.MaskType = DevExpress.XtraEditors.Mask.MaskType.Numeric
editor.Properties.Mask.EditMask = "N0"
editor.Properties.Mask.UseMaskAsDisplayFormat = True
editor.Parent = Me
trackBar.Parent = Me
' Set type of POCO-ViewModel
mvvmContext.ViewModelType = GetType(ViewModel)
' Data binding for the Progress property (via MVVMContext FluentAPI)
Dim fluent = mvvmContext.OfType(Of ViewModel)()
' Binding two integer properties - 'Value' and 'Progress'. No conversion needed
fluent.SetBinding(trackBar, Function(t) t.Value, Function(x) x.Progress)
' Binding the string 'Text' property to the integer 'Progress'. Values are automatically converted to/from an appropriate type.
fluent.SetBinding(editor, Function(e) e.Text, Function(x) x.Progress)
End Sub
Private Sub OnDisposing()
Dim context = MVVMContext.FromControl(Me)
If context IsNot Nothing Then
context.Dispose()
End If
End Sub
Public Class ViewModel
Public Overridable Property Progress() As Integer
End Class
End Class
End Namespace