title: Child Expanders raising Parent Expander's Expanded and Collapsed Events?
body: <p>For some reason, child <code>Expander</code>s (placed in a <code>StackPanel</code> inside of another <code>Expander</code>), when collapsed or expanded, cause the parent Expander to raise its <code>Expanded</code> or <code>Collapsed</code> events.</p>
  
  <p>Anyone know why this is or how I can change it? I'm only interested in the parent's events.</p>
  
  <p>Here is some test XAML:</p>
  
  
  
  <pre class="lang-xml prettyprint-override"><code>    &lt;Expander Header="Outer" Expanded="Expander_Expanded" Collapsed="Expander_Collapsed"&gt;
          &lt;StackPanel&gt;
              &lt;Expander Header="Inner1"&gt;
                  &lt;Canvas Height="100" Width="100" Background="Blue" /&gt;
              &lt;/Expander&gt;
              &lt;Expander Header="Inner2"&gt;
                  &lt;Canvas Height="100" Width="100" Background="Red" /&gt;
              &lt;/Expander&gt;
          &lt;/StackPanel&gt;
      &lt;/Expander&gt;
  </code></pre>
  
  <p>and here is the code-behind:</p>
  
  <pre><code>    private void Expander_Expanded(object sender, RoutedEventArgs e)
      {
          MessageBox.Show("expanded");
      }
  
      private void Expander_Collapsed(object sender, RoutedEventArgs e)
      {
          MessageBox.Show("collapsed");
      }
  </code></pre>
  
  <p>When you run this, if you expand the parent, you get an "expanded" messagebox, as you'd expect. But when you then expand one of the children, you get the messagebox again.</p>
  
  <p>The <a href="http://msdn.microsoft.com/en-us/library/system.windows.controls.expander.expanded.aspx">documentation</a> for the Expanded event says:</p>
  
  <blockquote>
    <p>The Expanded event occurs when the IsExpanded property changes from false to true</p>
  </blockquote>
  
  <p>But clearly the IsExpanded property isn't changing on the parent Expander.</p>
  
  <p>Why is this happening, any ideas?</p>