The checkbox is checked and unverified events are triggered when I select the expander

I just noticed this problem, whenever I select an expander whose parent flag it triggers checked / unverified events, even if the flag is not checked.

Here is a .gif that shows this is happening. The number in the upper right corner indicates the number of checked flags, I should just count up and down when the flag is checked or unchecked. However, the counter itself is not a concern, but simply a way to show how this happens.

For each flag, their Checked and UnChecked point to a method of my choice.

enter image description here

What causes this, and how can I prevent it?

Edit: XAML

  <Expander Loaded="VerifyExpanderLoaded" ExpandDirection="Down" IsExpanded="True" FontSize="14" FontWeight="Bold" Margin="5" BorderThickness="1" BorderBrush="#FF3E3D3D"> <Expander.Header> <DockPanel RenderTransformOrigin="0.5,0.5" LastChildFill="False" Margin="0" HorizontalAlignment="Stretch"> <TextBlock Text="Verify Caller and Account" DockPanel.Dock="Left" VerticalAlignment="Center" Margin="0"/> <Button DockPanel.Dock="Right" Margin="1,0" Click="VerifyUncheckAll"> <TextBlock Text="Uncheck All" Margin="1,0" FontSize="12" FontWeight="Normal"/> </Button> <Button DockPanel.Dock="Right" Margin="1,0" Click="VerifyCheckAll"> <TextBlock Text="Check All" FontSize="12" FontWeight="Normal" Margin="1,0"/> </Button> <TextBlock x:Name="VerifyCheckboxCount" Text="0/0" DockPanel.Dock="Right" VerticalAlignment="Center" FontSize="16" FontWeight="Bold" Margin="0,0,10,0"/> </DockPanel> </Expander.Header> <ListBox Background="{x:Null}" BorderBrush="{x:Null}"> <CheckBox x:Name="Authentication_CallerName_Checkbox" HorizontalAlignment="Center" Margin="10,5,0,0" Grid.ColumnSpan="2" FontSize="12" VerticalAlignment="Center" Checked="VerifyCheckBoxChecked" Unchecked="VerifyCheckBoxChecked"> <StackPanel Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Center"> <TextBlock Text="Caller Name" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="14"/> <StackPanel> <Expander ExpandDirection="Right" Margin="5,2,0,0" VerticalAlignment="Bottom" HorizontalAlignment="Right" FontSize="14"> <TextBlock Text="Obtain Callers Name " HorizontalAlignment="Center" Margin="0" VerticalAlignment="Center" FontWeight="Normal" FontStyle="Italic"> <Hyperlink x:Name="AuthenticationWikiLink" NavigateUri="[Redacted]" RequestNavigate="ExternalLinks"> Link </Hyperlink> </TextBlock> </Expander> </StackPanel> </StackPanel> </CheckBox> 
+5
source share
1 answer

What causes this?

I dont know. I assume this is due to redirected events. You could probably prevent this if you set eventArgs as handled in the correct event.

How can I prevent it?

First I use XAML. It is based on a simplified version of the one you posted.

 <CheckBox x:Name="checkbox" Checked="VerifyCheckBoxChecked" Unchecked="VerifyCheckBoxChecked"> <StackPanel Orientation="Horizontal"> <TextBlock Text="Test:" VerticalAlignment="Center"/> <StackPanel> <Expander ExpandDirection="Right" Margin="5,2,0,0" VerticalAlignment="Bottom" HorizontalAlignment="Right" FontSize="14" MouseEnter="Expander_MouseEnter" MouseLeave="Expander_MouseLeave"> <TextBlock Text="Open" VerticalAlignment="Center"/> </Expander> </StackPanel> </StackPanel> </CheckBox> 

And so .cs

 public partial class MainWindow : Window { bool mouseOverExpander = false; public MainWindow() { InitializeComponent(); } private void VerifyCheckBoxChecked(object sender, RoutedEventArgs e) { if (!mouseOverExpander) { if (true) ; } } private void Expander_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e) { mouseOverExpander = true; } private void Expander_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e) { mouseOverExpander = false; } } 

This does not prevent unwanted VerifyCheckBoxChecked calls, but filters them out.

0
source

All Articles