diff --git a/demo/Sandbox/Views/MainWindow.axaml b/demo/Sandbox/Views/MainWindow.axaml
index ba61022e3..d1f30fdcc 100644
--- a/demo/Sandbox/Views/MainWindow.axaml
+++ b/demo/Sandbox/Views/MainWindow.axaml
@@ -17,29 +17,17 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Ursa/Controls/DateTimePicker/DateTimePicker.cs b/src/Ursa/Controls/DateTimePicker/DateTimePicker.cs
index 6c5284403..43fafbb62 100644
--- a/src/Ursa/Controls/DateTimePicker/DateTimePicker.cs
+++ b/src/Ursa/Controls/DateTimePicker/DateTimePicker.cs
@@ -140,7 +140,7 @@ private void OnDateSelected(object? sender, CalendarDayButtonEventArgs e)
}
}
- private void OnTimeSelectedChanged(object sender, TimeChangedEventArgs e)
+ private void OnTimeSelectedChanged(object? sender, TimeChangedEventArgs e)
{
if (SelectedDate is null)
{
diff --git a/src/Ursa/Controls/DateTimePicker/TimePicker.cs b/src/Ursa/Controls/DateTimePicker/TimePicker.cs
index 5528bdb32..3eee8f762 100644
--- a/src/Ursa/Controls/DateTimePicker/TimePicker.cs
+++ b/src/Ursa/Controls/DateTimePicker/TimePicker.cs
@@ -93,7 +93,7 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
SyncTimeToText(SelectedTime);
}
- private void OnPresenterTimeChanged(object sender, TimeChangedEventArgs e)
+ private void OnPresenterTimeChanged(object? sender, TimeChangedEventArgs e)
{
if (_suppressTextPresenterEvent) return;
SetCurrentValue(SelectedTimeProperty, e.NewTime);
diff --git a/src/Ursa/Controls/DateTimePicker/TimeRangePicker.cs b/src/Ursa/Controls/DateTimePicker/TimeRangePicker.cs
index fae812cb8..ff0c7c012 100644
--- a/src/Ursa/Controls/DateTimePicker/TimeRangePicker.cs
+++ b/src/Ursa/Controls/DateTimePicker/TimeRangePicker.cs
@@ -156,7 +156,7 @@ protected override void OnApplyTemplate(TemplateAppliedEventArgs e)
SyncTimeToText(EndTime, false);
}
- private void OnPresenterTimeChanged(object sender, TimeChangedEventArgs e)
+ private void OnPresenterTimeChanged(object? sender, TimeChangedEventArgs e)
{
if (_suppressTextPresenterEvent) return;
SetCurrentValue(Equals(sender, _startPresenter) ? StartTimeProperty : EndTimeProperty, e.NewTime);
diff --git a/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs b/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs
index e4130e778..78268cf38 100644
--- a/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs
+++ b/src/Ursa/Controls/NumericUpDown/NumericUpDownBase.cs
@@ -26,6 +26,7 @@ public abstract class NumericUpDown : TemplatedControl, IClearControl, IInnerCon
protected ButtonSpinner? _spinner;
protected TextBox? _textBox;
protected internal Panel? _dragPanel;
+ private bool _isFocused;
private Point? _point;
protected internal bool _updateFromTextInput;
@@ -149,6 +150,7 @@ public bool ShowButtonSpinner
static NumericUpDown()
{
+ FocusableProperty.OverrideDefaultValue(true);
NumberFormatProperty.Changed.AddClassHandler((o, e) => o.OnFormatChange(e));
FormatStringProperty.Changed.AddClassHandler((o, e) => o.OnFormatChange(e));
IsReadOnlyProperty.Changed.AddClassHandler((o, args) => o.OnIsReadOnlyChanged(args));
@@ -216,6 +218,34 @@ protected override void OnLostFocus(RoutedEventArgs e)
{
_dragPanel.IsVisible = true;
}
+ FocusChanged(IsKeyboardFocusWithin);
+ }
+
+ protected override void OnGotFocus(GotFocusEventArgs e)
+ {
+ base.OnGotFocus(e);
+ FocusChanged(IsKeyboardFocusWithin);
+ }
+
+ private void FocusChanged(bool hasFocus)
+ {
+ // The OnGotFocus & OnLostFocus are asynchronously and cannot
+ // reliably tell you that have the focus. All they do is let you
+ // know that the focus changed sometime in the past. To determine
+ // if you currently have the focus you need to do consult the
+ // FocusManager.
+
+ bool wasFocused = _isFocused;
+ _isFocused = hasFocus;
+
+ if (hasFocus)
+ {
+
+ if (!wasFocused && _textBox != null)
+ {
+ _textBox.Focus();
+ }
+ }
}
protected override void OnKeyDown(KeyEventArgs e)
diff --git a/tests/HeadlessTest.Ursa/Controls/FormTests/Dynamic_Item_Generation/Test.cs b/tests/HeadlessTest.Ursa/Controls/FormTests/Dynamic_Item_Generation/Test.cs
index ed0266efc..5566ed4d9 100644
--- a/tests/HeadlessTest.Ursa/Controls/FormTests/Dynamic_Item_Generation/Test.cs
+++ b/tests/HeadlessTest.Ursa/Controls/FormTests/Dynamic_Item_Generation/Test.cs
@@ -26,6 +26,7 @@ public void FormItem_Generation()
window.Show();
var form = window.FindControl