Reputation: 331062
Is there a single event like Changed
that I can use to handle both events together?
Why are they separated like this?
Is it because having a single event for both would requires you to reference the control by name, which you would need to specify in the XAML, and this would increase the clutter?
Upvotes: 23
Views: 16756
Reputation: 505
For example to start a storyboard when checked and stop it when unchecked.
Upvotes: 1
Reputation: 108957
The split gives more granularity for those who need it (can't hurt for those who don't) and if you want you can handle both events with one handler.
<CheckBox Content="CheckBox" Name="checkBox1" Checked="checkBox1_changed" Unchecked="checkBox1_changed" />
Upvotes: 16
Reputation: 61437
IsChecked
property of the sender
parameter (after casting it to CheckBox
or ToggleButton
of course).EventTriggers
and similar. EventTriggers
can't distinguish between state, only by event, so two different events are needed.On a general note: I wouldn't use the events at all - I would bind the IsChecked
property to an appropiate property on your ViewModel
, keeping your code-behind to a minimum (Ideally no custom code at all).
Upvotes: 29