internal void TryFocus()
{
// if subclass doesn't override OnFocus then try to find a focusable control ourselves.
var focusMethod = this.GetType().GetMethod("OnFocus", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance);
if (focusMethod != null && focusMethod.DeclaringType != typeof(DialogControl))
{
OnFocus();
}
else
{
this.ProcessInVisualTree<FrameworkElement>(fe =>
{
var matches = fe.Visibility == System.Windows.Visibility.Visible && fe.IsEnabled && fe.Focusable;
if (matches)
{
fe.Focus();
}
return matches;
});
}
}