Facing problems for Databind the Password Property of a WPF PasswordBox

Posted by Ray.Chayan under WPF on 1/10/2013 | Points: 10 | Views : 1360 | Status : [Member] | Replies : 1
Hi I am new in WPF and facing problems for Databind the Password Property of a WPF PasswordBox. I found some code in this url http://wpftutorial.net/PasswordBox.html
but the whole code is in C#.net.

As my code is in vb.net have converted the code but it is not working . Can you please help me in this regard. My code in vb.net is given bellow.


'Public Class PasswordHelper

' Shared PasswordProperty As DependencyProperty
' Shared AttachProperty As DependencyProperty
' Shared IsUpdatingProperty As DependencyProperty

' Public Sub New()
' MyBase.New()
' PasswordProperty = DependencyProperty.RegisterAttached("Password", GetType(System.String), GetType(PasswordHelper), New FrameworkPropertyMetadata(String.Empty, AddressOf OnPasswordPropertyChanged))
' AttachProperty = DependencyProperty.RegisterAttached("Attach", GetType(System.Boolean), GetType(PasswordHelper), New PropertyMetadata(False, AddressOf Attach))
' IsUpdatingProperty = DependencyProperty.RegisterAttached("IsUpdating", GetType(System.Boolean), GetType(PasswordHelper))
' End Sub



' Public Shared Sub SetAttach(ByVal dp As DependencyObject, ByVal value As Boolean)
' dp.SetValue(AttachProperty, value)
' End Sub



' Public Shared Function GetAttach(ByVal dp As DependencyObject) As Boolean
' Return CType(dp.GetValue(AttachProperty), Boolean)
' End Function


' Public Shared Function GetPassword(ByVal dp As DependencyObject) As String
' Return CType(dp.GetValue(PasswordProperty), String)
' End Function


' Public Shared Sub SetPassword(ByVal dp As DependencyObject, ByVal value As String)
' dp.SetValue(PasswordProperty, value)
' End Sub



' Private Shared Function GetIsUpdating(ByVal dp As DependencyObject) As Boolean
' Return CType(dp.GetValue(IsUpdatingProperty), Boolean)
' End Function


' Private Shared Sub SetIsUpdating(ByVal dp As DependencyObject, ByVal value As Boolean)
' dp.SetValue(IsUpdatingProperty, value)
' End Sub


' Private Shared Sub OnPasswordPropertyChanged(ByVal sender As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
' Dim passwordBox As Controls.PasswordBox = CType(sender, Controls.PasswordBox)
' 'passwordBox.PasswordChanged -= PasswordChanged;
' RemoveHandler passwordBox.PasswordChanged, AddressOf PasswordChanged


' If Not CType(GetIsUpdating(passwordBox), Boolean) Then
' passwordBox.Password = CType(e.NewValue, String)
' End If

' AddHandler passwordBox.PasswordChanged, AddressOf PasswordChanged
' End Sub



' Private Sub Attach(ByVal sender As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
' Dim passwordBox As Controls.PasswordBox = CType(sender, Controls.PasswordBox)
' If (passwordBox Is Nothing) Then
' Return
' End If
' If CType(e.OldValue, Boolean) Then
' RemoveHandler passwordBox.PasswordChanged, AddressOf PasswordChanged
' End If
' If CType(e.NewValue, Boolean) Then
' AddHandler passwordBox.PasswordChanged, AddressOf PasswordChanged
' End If
' End Sub



' Private Shared Sub PasswordChanged(ByVal sender As Object, ByVal e As RoutedEventArgs)
' Dim passwordBox As Controls.PasswordBox = CType(sender, Controls.PasswordBox)
' SetIsUpdating(passwordBox, True)
' SetPassword(passwordBox, passwordBox.Password)
' SetIsUpdating(passwordBox, False)
' End Sub



'End Class




Responses

Posted by: Kundan64 on: 1/16/2013 [Member] Starter | Points: 25

Up
0
Down
What problem is coming in your code and where, pls explain.

Ray.Chayan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response