Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class PasswordBoxBindingBehavior : Behavior<PasswordBox>
- {
- protected override void OnAttached()
- {
- AssociatedObject.PasswordChanged += OnPasswordBoxValueChanged;
- }
- public SecureString Password
- {
- get { return (SecureString)GetValue(PasswordProperty); }
- set { SetValue(PasswordProperty, value); }
- }
- public static readonly DependencyProperty PasswordProperty =
- DependencyProperty.Register("Password", typeof(SecureString), typeof(PasswordBoxBindingBehavior), new PropertyMetadata(null));
- private void OnPasswordBoxValueChanged(object sender, RoutedEventArgs e)
- {
- Password = AssociatedObject.SecurePassword;
- }
- }
- // usage xaml
- <PasswordBox>
- <i:Interaction.Behaviors>
- <behavior:PasswordBoxBindingBehavior
- Password="{Binding Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />
- </i:Interaction.Behaviors>
- </PasswordBox>
- // usage VM
- public SecureString Password
- {
- get { return _password.Value; }
- set { this.SetProperty(_password, value); }
- }
Advertisement
Add Comment
Please, Sign In to add comment