using System.Windows.Controls; using System.Windows.Input; using System.Windows.Threading; namespace Chronos.App.Sections; public partial class WelcomeView : UserControl { public WelcomeView() { InitializeComponent(); IsVisibleChanged += (_, e) => { if (e.NewValue is true) Dispatcher.InvokeAsync(FocusChoice, DispatcherPriority.Input); }; } /// /// The dialog opens with focus on the chosen card, so the keyboard starts inside it; the window keeps it as its focused /// element, so a window not active yet gives the card keyboard focus when activated. /// private void FocusChoice() { var chosen = new[] { LocalChoice, AdoptChoice, ServerChoice }.FirstOrDefault(c => c.IsChecked == true) ?? LocalChoice; FocusManager.SetFocusedElement(FocusManager.GetFocusScope(chosen), chosen); Keyboard.Focus(chosen); } }