title: Set focus back to its parent?
body: <p>From post <a href="https://stackoverflow.com/questions/2914495/wpf-how-to-programmatically-remove-focus-from-a-textbox">WPF: How to programmatically remove focus from a TextBox</a>, I know how to set a <code>TextBox</code>'s focus back to its parent using the following code:</p>
  
  <pre><code>// Move to a parent that can take focus
  FrameworkElement parent = (FrameworkElement)textBox.Parent;
  while (parent != null &amp;&amp; parent is IInputElement 
                        &amp;&amp; !((IInputElement)parent).Focusable)
  {
      parent = (FrameworkElement)parent.Parent;
  }
  
  DependencyObject scope = FocusManager.GetFocusScope(textBox);
  FocusManager.SetFocusedElement(scope, parent as IInputElement);
  </code></pre>
  
  <p>Is there any way to generalize this code (like template functions) to make it also work for other items like <code>ComboBox</code>, <code>Canvas</code>, <code>Image</code> etc.</p>