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
| Public Class MyControl
Inherits UserControl
Public Sub New()
' Cet appel est requis par le concepteur.
InitializeComponent()
' Ajoutez une initialisation quelconque après l'appel InitializeComponent().
Me.PwdBox = Me.pass
End Sub
Public Property PwdBox As PasswordBox
Get
Return GetValue(PwdBoxProperty)
End Get
Set(ByVal value As PasswordBox)
SetValue(PwdBoxProperty, value)
End Set
End Property
Public Shared ReadOnly PwdBoxProperty As DependencyProperty = _
DependencyProperty.Register("PwdBox", _
GetType(PasswordBox), GetType(MyControl), _
New FrameworkPropertyMetadata(Nothing, AddressOf OnPwdBoxChanged))
Private Shared Sub OnPwdBoxChanged(d As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim ctl As MyControl = CType(d, MyControl)
Dim PassBox As PasswordBox = CType(e.NewValue, PasswordBox)
If (PassBox IsNot Nothing) Then ctl.ProcessPwd(PassBox)
End Sub
Private Sub ProcessPwd(passbox As PasswordBox)
AddHandler passbox.PasswordChanged, AddressOf OnPassBoxChanged
End Sub
Private Sub OnPassBoxChanged(sender As Object, e As RoutedEventArgs)
Dim pd As PasswordBox = CType(sender, PasswordBox)
Code = pd.Password
End Sub
Public Property Code As String
Get
Return GetValue(CodeProperty)
End Get
Set(ByVal value As String)
SetValue(CodeProperty, value)
End Set
End Property
Public Shared ReadOnly CodeProperty As DependencyProperty = _
DependencyProperty.Register("Code", _
GetType(String), GetType(MyControl), _
New FrameworkPropertyMetadata(Nothing, AddressOf OnCodeChanged))
Private Shared Sub OnCodeChanged(d As DependencyObject, e As DependencyPropertyChangedEventArgs)
Dim ctl As MyControl = CType(d, MyControl)
Dim s As String = CType(e.NewValue, String)
If (s IsNot Nothing) Then
ctl.PwdBox.Password = s
End If
End Sub
End Class |
Partager