public override void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { // get the caller PasswordBox passwordBox = sender as PasswordBox; // make sure it is a password box if (passwordBox == null) { return; } // remuve any previus events passwordBox.PasswordChanged -= PasswordBox_PasswordChanged; // if the caller set MonitorPassword to true... if ((bool)e.NewValue) { // set default value HasTextProperty.SetValue(passwordBox); // start listening out for password changes passwordBox.PasswordChanged += PasswordBox_PasswordChanged; } }
// Fired when the password box password value changes private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e) { // set the attached HasText value HasTextProperty.SetValue((PasswordBox)sender); }