For some reason, a child Expander (placed in a StackPanel inside another Expander ), when minimized or expanded, causes the parent Expander to raise Expanded or Collapsed events.
Does anyone know why this is or how I can change it? I'm only interested in parenting events.
Here are some XAML tests:
<Expander Header="Outer" Expanded="Expander_Expanded" Collapsed="Expander_Collapsed"> <StackPanel> <Expander Header="Inner1"> <Canvas Height="100" Width="100" Background="Blue" /> </Expander> <Expander Header="Inner2"> <Canvas Height="100" Width="100" Background="Red" /> </Expander> </StackPanel> </Expander>
and here is the code:
private void Expander_Expanded(object sender, RoutedEventArgs e) { MessageBox.Show("expanded"); } private void Expander_Collapsed(object sender, RoutedEventArgs e) { MessageBox.Show("collapsed"); }
When you run this, if you disassemble the parent, you will get an "extended" mailbox, as you would expect. But when you later expand one of the children, you again get a message.
The documentation for the extended event states:
The Expanded event occurs when the IsExpanded property changes from false to true.
But explicitly, the IsExpanded property does not change on the parent expander.
Why is this happening, any ideas?
source share