I have a lots of controls in a Window including checkboxes and comboboxes. I want to track CheckBox.IsChecked event, so I defined an event handler in Windows level as
<Grid CheckBox.Checked="OnModified" CheckBox.Unchecked="OnModified">
The problem is that the same event is also fired by ComboBox right after mouse clicking an item. I thought my event handler should only capture CheckBox's Checked event, not ToggleButton's. Did I miss anything?
EDIT: As I pointed out below, I thought it would work this way because I read Matthew MacDonald's book "Pro WPF in C# 2010". On page 164, he gave this example code first:
<StackPanel Button.Click="DoSomething" Margin="5">
<Button Name="cmd1">Command 1</Button>
<Button Name="cmd2">Command 2</Button>
<Button Name="cmd3">Command 3</Button>
...
</StackPanel>
Then, he specially noted:
Note The Click event is actually defined in the ButtonBase class and inherited by the Button class. If you attach an event handler to ButtonBase.Click, that event handler will be used when any ButtonBase-derived control is clicked (including the Button, RadioButton, and CheckBox classes). If you attach an event handler to Button.Click, it’s only used for Button objects.
Now, did I misunderstand him, or is his note wrong?