47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using Microsoft.Xaml.Behaviors;
|
|
using System.Windows;
|
|
using Telerik.Windows.Controls;
|
|
|
|
namespace SWS.Commons
|
|
{
|
|
public class PasswordBoxBehavior : Behavior<RadPasswordBox>
|
|
{
|
|
public static readonly DependencyProperty PasswordProperty =
|
|
DependencyProperty.Register(nameof(Password), typeof(string), typeof(PasswordBoxBehavior),
|
|
new FrameworkPropertyMetadata(string.Empty, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnPasswordChanged));
|
|
|
|
public string Password
|
|
{
|
|
get { return (string)GetValue(PasswordProperty); }
|
|
set { SetValue(PasswordProperty, value); }
|
|
}
|
|
|
|
protected override void OnAttached()
|
|
{
|
|
base.OnAttached();
|
|
AssociatedObject.PasswordChanged += OnPasswordChanged;
|
|
}
|
|
|
|
protected override void OnDetaching()
|
|
{
|
|
base.OnDetaching();
|
|
AssociatedObject.PasswordChanged -= OnPasswordChanged;
|
|
}
|
|
|
|
private void OnPasswordChanged(object sender, RoutedEventArgs e)
|
|
{
|
|
Password = AssociatedObject.Password;
|
|
}
|
|
|
|
private static void OnPasswordChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
|
{
|
|
if (d is PasswordBoxBehavior behavior)
|
|
{
|
|
behavior.AssociatedObject.Password = e.NewValue as string ?? string.Empty;
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
}
|