-
Notifications
You must be signed in to change notification settings - Fork 2
/
PassingParametersToCommandsUserControl.vb
69 lines (63 loc) · 2.85 KB
/
PassingParametersToCommandsUserControl.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
Imports DevExpress.Mvvm
Imports DevExpress.Mvvm.POCO
Imports DevExpress.Utils.MVVM
Imports DevExpress.XtraEditors
Imports DevExpress.XtraEditors.Controls
Imports System
Imports System.Drawing
Imports System.Windows.Forms
Namespace DxSampleEventToCommandBehaviorParametersConverters
Partial Public Class PassingParametersToCommandsUserControl
Inherits DevExpress.XtraEditors.XtraUserControl
Public Sub New()
InitializeComponent()
Dim mvvmContext As New MVVMContext()
mvvmContext.ContainerControl = Me
Dim panel As New PanelControl()
panel.Dock = DockStyle.Top
panel.Parent = Me
Dim label As New LabelControl()
label.Text = "Click to Execute Command"
label.Dock = DockStyle.Fill
label.AutoSizeMode = LabelAutoSizeMode.None
label.Appearance.TextOptions.HAlignment = DevExpress.Utils.HorzAlignment.Center
label.Appearance.TextOptions.VAlignment = DevExpress.Utils.VertAlignment.Center
label.Parent = panel
mvvmContext.ViewModelType = GetType(MouseDownAwareViewModel)
' UI binding for the EventToCommand behavior
mvvmContext.OfType(Of MouseDownAwareViewModel)().WithEvent(Of MouseEventArgs)(label, "MouseDown").
EventToCommand(Sub(x) x.Report(Nothing), Function(x) x.Message)
End Sub
Private Sub OnDisposing()
Dim context = MVVMContext.FromControl(Me)
If context IsNot Nothing Then
context.Dispose()
End If
End Sub
Public Class MouseDownAwareViewModel
Public Sub New()
Message = "MouseDown performed!"
End Sub
Public Property Message() As String
Protected ReadOnly Property MessageBoxService() As IMessageBoxService
Get
Return Me.GetService(Of IMessageBoxService)()
End Get
End Property
Public Sub Report(ByVal message As String)
MessageBoxService.ShowMessage(message)
End Sub
Public Sub ReportArgs(ByVal args As MouseEventArgs)
Dim msg As String = String.Join(", ",
"Button: " & args.Button.ToString(),
"Location: " & args.Location.ToString(),
"Clicks: " & args.Clicks.ToString(),
"Delta: " & args.Delta.ToString())
MessageBoxService.ShowMessage("Args = {" & msg & "}")
End Sub
Public Sub ReportLocation(ByVal pt As Point)
MessageBoxService.ShowMessage("Location = " & pt.ToString())
End Sub
End Class
End Class
End Namespace