title: Why does ItemsControl show a focus rectangle when its parent is focused?
body: <p>WPF's ItemsControl will display a focus rectangle when it thinks it has focus and the user presses Tab or Alt.</p>
  
  <p>But I recently had an ItemsControl display a focus rectangle even though it <em>did not have focus</em> -- one of its parents did. The ItemsControl was inside a UserControl, which was inside another UserControl that <em>did</em> have focus. Something like this:</p>
  
  <pre><code>&lt;!-- UserControl1.xaml; this is the control that has focus --&gt;
  &lt;UserControl x:Class="UserControl1" Focusable="True" ...&gt;
      &lt;UserControl2/&gt;
  &lt;/UserControl&gt;
  
  &lt;!-- UserControl2.xaml --&gt;
  &lt;UserControl x:Class="UserControl2"&gt;
      &lt;ItemsControl .../&gt;
  &lt;/UserControl&gt;
  </code></pre>
  
  <p>Or, to show the nesting visually:</p>
  
  <pre><code>+---------------------------------------------------+
  | UserControl1 (has focus)                          |
  |                                                   |
  | +-----------------------------------------------+ |
  | | UserControl2                                  | |
  | |                                               | |
  | | +-------------------------------------------+ | |
  | | | ItemsControl (shows focus rectangle)      | | |
  </code></pre>
  
  <p>It took me a while (and a <a href="https://stackoverflow.com/questions/818566/remove-focus-rectangle-on-a-usercontrol">StackOverflow question</a>) to figure out where the focus rectangle was coming from, because I never expected a control that didn't have focus to show a focus rectangle.</p>
  
  <p>I'm still learning my way around WPF, and obviously I don't know enough yet, or this wouldn't have confused me. Two questions to help me understand:</p>
  
  <ol>
  <li><em>Why</em> does ItemsControl display a focus rectangle when it doesn't actually have focus, but one of its parent controls does? What's the reason for this feature? (I'm sure there is one -- maybe something to do with templates or visual trees? -- I just don't have a deep enough understanding of WPF mechanics and philosophy yet.)</li>
  <li><em>How</em> does this work? What's the mechanism ItemsControl uses to decide that it should display a focus rectangle?</li>
  </ol>