public override void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { if (sender is PasswordBox passwordBox) { //Remove any previous evens passwordBox.PasswordChanged -= PasswordBoxOnPasswordChanged; //If the caller set MonitorPassword to true... if (e.NewValue is bool flag && flag) { HasTextProperty.SetValue(passwordBox); //start listening out for password changes passwordBox.PasswordChanged += PasswordBoxOnPasswordChanged; } } }
private void PasswordBoxOnPasswordChanged(object sender, RoutedEventArgs e) { HasTextProperty.SetValue((PasswordBox)sender); }