Ejemplo n.º 1
0
 private static void OnSelectedAllOnGotFocusPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
 {
     if (d is TextBox)
     {
         TextBox box = d as TextBox;
         if ((bool)e.NewValue)
         {
             box.AddHandler(TextBox.PreviewMouseDownEvent, new MouseButtonEventHandler(TextBox_PreviewMouseDown));
             box.AddHandler(TextBox.GotFocusEvent, new RoutedEventHandler(TextBox_GotFocus));
             box.AddHandler(TextBox.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus));
         }
         else
         {
             box.RemoveHandler(TextBox.MouseUpEvent, new MouseButtonEventHandler(TextBox_PreviewMouseDown));
             box.RemoveHandler(TextBox.GotFocusEvent, new RoutedEventHandler(TextBox_GotFocus));
             box.RemoveHandler(TextBox.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus));
         }
     }
     else if (d is PasswordBox)
     {
         PasswordBox box = d as PasswordBox;
         if ((bool)e.NewValue)
         {
             box.AddHandler(PasswordBox.PreviewMouseDownEvent, new MouseButtonEventHandler(TextBox_PreviewMouseDown));
             box.AddHandler(PasswordBox.GotFocusEvent, new RoutedEventHandler(TextBox_GotFocus));
             box.AddHandler(PasswordBox.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus));
         }
         else
         {
             box.RemoveHandler(PasswordBox.MouseUpEvent, new MouseButtonEventHandler(TextBox_PreviewMouseDown));
             box.RemoveHandler(PasswordBox.GotFocusEvent, new RoutedEventHandler(TextBox_GotFocus));
             box.RemoveHandler(PasswordBox.LostFocusEvent, new RoutedEventHandler(TextBox_LostFocus));
         }
     }
 }
Ejemplo n.º 2
0
 public static void RemovePasswordChangedHandler(this PasswordBox passBox, RoutedEventHandler handler)
 {
     passBox.RemoveHandler(MirrorPasswordChangedEvent, handler);
 }