How to convert the Checkbox.checked routed event to the command for MVVM pattern?
Reference-Consider the button click routed event, When we assign the command for button then button.click event is considered as command. It executes respective that command.
I googled for it, i got the solution with EventBehaviourFactory. Is it possible without using the EventBehaiourFactory?
It is a common requirement in WPF. The most widely used solution is using Interactivity
from the Blend SDK:
Add this xmlns namespace to your xaml:
xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
Then you can do:
<CheckBox>
<i:Interaction.Triggers>
<i:EventTrigger EventName="Checked">
<i:InvokeCommandAction Command="{Binding MyCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
</CheckBox>
Of course, you need to add System.Windows.Interactivity.dll to your project, located (for me at least) at: C:\Program Files (x86)\Microsoft SDKs\Expression\Blend 3\Interactivity\Libraries\WPF\System.Windows.Interactivity.dll
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With