private void Box_PasswordChanged(object sender, RoutedEventArgs e) { PasswordBox box = sender as PasswordBox; box.SetValue(UpdatingProperty.ValueProperty, true); box.SetValue(BoundPasswordProperty.ValueProperty, box.Password); box.SetValue(UpdatingProperty.ValueProperty, false); HasPasswordProperty.SetValue(box); }
public override void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { PasswordBox box = sender as PasswordBox; if (box == null) { return; } if ((bool)e.OldValue) { box.PasswordChanged -= Box_PasswordChanged; } if ((bool)e.NewValue) { box.PasswordChanged += Box_PasswordChanged; HasPasswordProperty.SetValue(box); } }