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 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 text changes passwordBox.PasswordChanged += PasswordBox_PasswordChanged; } }
/// <summary> /// Fired when the text box changed /// </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); }
/// <summary> /// Fired when the text box changed /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void TextBox_TextChanged(object sender, TextChangedEventArgs e) { // Set the attached HasText value HasTextProperty.SetValue((TextBox)sender); }