diff --git a/samples/ControlCatalog/Pages/DataGridPage.xaml b/samples/ControlCatalog/Pages/DataGridPage.xaml
index 451a774cb4..f7e3cf2441 100644
--- a/samples/ControlCatalog/Pages/DataGridPage.xaml
+++ b/samples/ControlCatalog/Pages/DataGridPage.xaml
@@ -72,7 +72,7 @@
-
+
diff --git a/samples/ControlCatalog/Pages/DataGridPage.xaml.cs b/samples/ControlCatalog/Pages/DataGridPage.xaml.cs
index ec2c6651de..c010d38eac 100644
--- a/samples/ControlCatalog/Pages/DataGridPage.xaml.cs
+++ b/samples/ControlCatalog/Pages/DataGridPage.xaml.cs
@@ -6,7 +6,9 @@ using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using ControlCatalog.Models;
using Avalonia.Collections;
+using Avalonia.Controls.Primitives;
using Avalonia.Data;
+using Avalonia.Threading;
namespace ControlCatalog.Pages
{
@@ -84,5 +86,19 @@ namespace ControlCatalog.Pages
return Comparer.Default.Compare(x, y);
}
}
+
+ private void NumericUpDown_OnTemplateApplied(object sender, TemplateAppliedEventArgs e)
+ {
+ // We want to focus the TextBox of the NumericUpDown. To do so we search for this control when the template
+ // is applied, but we postpone the action until the control is actually loaded.
+ if (e.NameScope.Find("PART_TextBox") is {} textBox)
+ {
+ Dispatcher.UIThread.InvokeAsync(() =>
+ {
+ textBox.Focus();
+ textBox.SelectAll();
+ }, DispatcherPriority.Loaded);
+ }
+ }
}
}