![]() |
![]() | ![]() | ![]() | ![]() | ![]() | ![]() | ![]() |
| Welcome to Windows Vista Forums. Our forum is dedicated to helping you find solutions with any problems, errors or issues you are experiencing with Windows Vista. The Vista forum also covers news and updates and has an extensive Windows Vista tutorial section that covers a wide range of tips and tricks. |
| |||||||
| |
| | #1 (permalink) |
| | Problem with autoselecting text on getting focus For our application, the desired behavior is when a text box is getting a focus, all text within that text box is automatically selected, so user can just start typing, saving keystrokes. I couldn't find a property that controls this behavior, so I just attached an event to the text box: edPrice.GotFocus += delegate(object sender, RoutedEventArgs e) { edPrice.SelectAll(); }; Unfortunately, this works only if the focus is received through keyboard navigation, if a text box is selected with a mouse, the selection disappears as soon as mouse button is released. Handling the PreviewMouseLeftButtonUp (setting event argument's Handled to true) helped, but completely broke mouse navigation. Re-selecting the text in MouseLeftButtonUp also got me nowhere. Any suggestions? |
My System Specs![]() |
| | #2 (permalink) |
| | Re: Problem with autoselecting text on getting focus Hi, You could try something like the following, it's simple, but has problem when losing the focus with the mouse. The next item will require two mouse clicks instead of one to get the focus out of the MyTextBox instance. class MyTextBox: TextBox { bool isGettingFocus; protected override void OnPreviewMouseUp(System.Windows.Input.MouseButtonEventArgs e) { if (isGettingFocus) { isGettingFocus = false; e.Handled = true; } else base.OnPreviewMouseUp(e); } protected override void OnGotKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventArgs e) { base.OnGotKeyboardFocus(e); this.SelectAll(); } protected override void OnPreviewGotKeyboardFocus(System.Windows.Input.KeyboardFocusChangedEventArgs e) { base.OnPreviewGotKeyboardFocus(e); isGettingFocus = true; } } Luc |
My System Specs![]() |
| Thread Tools | |
| |
Similar Threads | ||||
| Thread | Forum | |||
| wierd focus problem | Microsoft Office | |||
| Text processing problem | PowerShell | |||
| Text display problem HELP PLEASE | Vista General | |||
| WPF ListView focus problem. | .NET General | |||
| keyboard problem: text goes everywhere | Vista hardware & devices | |||