19 using System.Collections.Generic;
23 using System.Windows.Controls;
24 using System.Windows.Input;
25 using System.Windows.Media;
31 #region Public methods 42 EventManager.RegisterClassHandler(typeof(TextBox), TextBox.PreviewMouseLeftButtonDownEvent,
43 new MouseButtonEventHandler(SelectivelyIgnoreMouseButton));
44 EventManager.RegisterClassHandler(typeof(TextBox), TextBox.GotKeyboardFocusEvent,
45 new RoutedEventHandler(SelectAllText));
46 EventManager.RegisterClassHandler(typeof(TextBox), TextBox.MouseDoubleClickEvent,
47 new RoutedEventHandler(SelectAllText));
52 #region Private methods 54 static void SelectivelyIgnoreMouseButton(
object sender, MouseButtonEventArgs e)
57 DependencyObject parent = e.OriginalSource as UIElement;
58 while (parent != null && !(parent is TextBox))
59 parent = VisualTreeHelper.GetParent(parent);
63 var textBox = (TextBox)parent;
64 if (!textBox.IsKeyboardFocusWithin)
74 static void SelectAllText(
object sender, RoutedEventArgs e)
76 var textBox = e.OriginalSource as TextBox;
static void RegisterTextBoxSelectAll()
Make text boxes select all text on focus.