public override void OnValueChanged(DependencyObject sender, DependencyPropertyChangedEventArgs e) { // get the caller var passwordBox = sender as PasswordBox; // make sure it is a passwordBox if (passwordBox == null) { return; } // remove any previous event passwordBox.PasswordChanged -= PasswordBox_PasswordChanged; // if the caller set MonitorPassword to true if ((bool)e.NewValue) { // set default property HasTextProperty.SetValue(passwordBox); // start listening out for password changes passwordBox.PasswordChanged += PasswordBox_PasswordChanged; } }
/// <summary> /// fired when the password box password value changes /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e) { // set the attached HasText value HasTextProperty.SetValue((PasswordBox)sender); }