19 using System.Collections.Generic;
23 using System.Windows.Controls;
24 using System.Windows.Input;
37 public static readonly DependencyProperty FocusFirstProperty =
38 DependencyProperty.RegisterAttached(
42 new PropertyMetadata(
false, OnFocusFirstPropertyChanged));
44 public static bool GetFocusFirst(Control control)
46 return (
bool)control.GetValue(FocusFirstProperty);
49 public static void SetFocusFirst(Control control,
bool value)
51 control.SetValue(FocusFirstProperty, value);
54 static void OnFocusFirstPropertyChanged(
55 DependencyObject obj, DependencyPropertyChangedEventArgs args)
57 Control control = obj as Control;
58 if (control == null || !(args.NewValue is
bool))
63 if ((
bool)args.NewValue)
65 control.Loaded += (sender, e) =>
66 control.MoveFocus(
new TraversalRequest(FocusNavigationDirection.Next));
Focuses the first control in a window.