Skip to content

Commit e82c366

Browse files
authored
Added select all text on focus for TimePicker (#1792)
1 parent ffb48f0 commit e82c366

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

MaterialDesignThemes.Wpf/TimePicker.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,29 @@ public class TimePicker : Control
3232
static TimePicker()
3333
{
3434
DefaultStyleKeyProperty.OverrideMetadata(typeof(TimePicker), new FrameworkPropertyMetadata(typeof(TimePicker)));
35+
EventManager.RegisterClassHandler(typeof(TimePicker), UIElement.GotFocusEvent, new RoutedEventHandler(OnGotFocus));
36+
}
37+
38+
/// <summary>
39+
/// Called when this element gets focus.
40+
/// </summary>
41+
private static void OnGotFocus(object sender, RoutedEventArgs e)
42+
{
43+
// When TimePicker gets focus move it to the TextBox
44+
TimePicker picker = (TimePicker)sender;
45+
if ((!e.Handled) && (picker._textBox != null))
46+
{
47+
if (e.OriginalSource == picker)
48+
{
49+
picker._textBox.Focus();
50+
e.Handled = true;
51+
}
52+
else if (e.OriginalSource == picker._textBox)
53+
{
54+
picker._textBox.SelectAll();
55+
e.Handled = true;
56+
}
57+
}
3558
}
3659

3760
public TimePicker()

0 commit comments

Comments
 (0)