/// <summary> /// Sets focus on an element. /// </summary> /// <param name="element">The element to set focus on.</param> protected static void SetFocus(UIElement element) { FrameworkElementAutomationPeer elementPeer = FrameworkElementAutomationPeer.CreatePeerForElement(element) as FrameworkElementAutomationPeer; if (elementPeer.IsKeyboardFocusable()) { elementPeer.SetFocus(); } }