-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTextBoxValueBinding.cls
43 lines (36 loc) · 1.26 KB
/
TextBoxValueBinding.cls
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
VERSION 1.0 CLASS
BEGIN
MultiUse = -1 'True
END
Attribute VB_Name = "TextBoxValueBinding"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = False
'@Folder MVVM.Infrastructure.Binding
Option Explicit
Implements IHandlePropertyChanged
Private WithEvents UI As msForms.Textbox
Attribute UI.VB_VarHelpID = -1
Private Type TBinding
Source As Object
SourceProperty As String
End Type
Private this As TBinding
Public Sub Initialize(ByVal Control As msForms.Textbox, ByVal Source As Object, ByVal SourceProperty As String)
Set UI = Control
Set this.Source = Source
this.SourceProperty = SourceProperty
If TypeOf Source Is INotifyPropertyChanged Then RegisterPropertyChanges Source
End Sub
Private Sub RegisterPropertyChanges(ByVal Source As INotifyPropertyChanged)
Source.RegisterHandler Me
End Sub
Private Sub IHandlePropertyChanged_OnPropertyChanged(ByVal Source As Object, ByVal Name As String)
If Source Is this.Source And Name = this.SourceProperty Then
UI.Text = VBA.Interaction.CallByName(this.Source, this.SourceProperty, VbGet)
End If
End Sub
Private Sub UI_Change()
VBA.Interaction.CallByName this.Source, this.SourceProperty, VbLet, UI.value
End Sub