private static void IsFocusedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var fe = (FrameworkElement)d; if (e.OldValue == null) { fe.GotFocus += FrameworkElement_GotFocus; fe.LostFocus += FrameworkElement_LostFocus; } if (!fe.IsVisible) { fe.IsVisibleChanged += new DependencyPropertyChangedEventHandler(fe_IsVisibleChanged); } if ((bool)e.NewValue) { ProcessDesigner.UserControls.ComboBoxCus combo = fe as ProcessDesigner.UserControls.ComboBoxCus; ProcessDesigner.UserControls.ComboBoxWithSearch combosearch = fe as ProcessDesigner.UserControls.ComboBoxWithSearch; ProcessDesigner.UserControls.DatePickerCus datepic = fe as ProcessDesigner.UserControls.DatePickerCus; if (combo != null) { ((System.Windows.Controls.TextBox)combo.FindName("txtCombobox")).Focus(); } else if (combosearch != null) { ((System.Windows.Controls.TextBox)combosearch.FindName("txtCombobox")).Focus(); } else if (datepic != null) { ((System.Windows.Controls.TextBox)datepic.FindName("txtDate")).Focus(); } else { fe.Focus(); } } }