Veikedo

Untitled

Nov 1st, 2016
257
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.32 KB | None | 0 0
  1.     public class PasswordBoxBindingBehavior : Behavior<PasswordBox>
  2.     {
  3.         protected override void OnAttached()
  4.         {
  5.             AssociatedObject.PasswordChanged += OnPasswordBoxValueChanged;
  6.         }
  7.  
  8.         public SecureString Password
  9.         {
  10.             get { return (SecureString)GetValue(PasswordProperty); }
  11.             set { SetValue(PasswordProperty, value); }
  12.         }
  13.  
  14.         public static readonly DependencyProperty PasswordProperty =
  15.             DependencyProperty.Register("Password", typeof(SecureString), typeof(PasswordBoxBindingBehavior), new PropertyMetadata(null));
  16.  
  17.  
  18.         private void OnPasswordBoxValueChanged(object sender, RoutedEventArgs e)
  19.         {
  20.             Password = AssociatedObject.SecurePassword;
  21.         }
  22.     }
  23.  
  24.  
  25. // usage  xaml
  26.                     <PasswordBox>
  27.                         <i:Interaction.Behaviors>
  28.                             <behavior:PasswordBoxBindingBehavior
  29.                                 Password="{Binding Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
  30.                         </i:Interaction.Behaviors>
  31.                     </PasswordBox>
  32.  
  33.  
  34. // usage VM
  35.         public SecureString Password
  36.         {
  37.             get { return _password.Value; }
  38.             set { this.SetProperty(_password, value); }
  39.         }
Advertisement
Add Comment
Please, Sign In to add comment