SO i have CheckBox and since there's no CheckBox.PerformClick() method in WPF, is there a way to click a WPF CheckBox programmatically?
I found this solution but this for Button only:
ButtonAutomationPeer peer = new ButtonAutomationPeer(someButton);
IInvokeProvider invokeProv = peer.GetPattern(PatternInterface.Invoke) as IInvokeProvider;
invokeProv.Invoke();
You may use the PatternInterface.Toggle interface to toggle the CheckBox:
CheckBoxAutomationPeer peer = new CheckBoxAutomationPeer(someCheckBox);
IToggleProvider toggleProvider = peer.GetPattern(PatternInterface.Toggle) as IToggleProvider;
toggleProvider.Toggle();
Or you can set the IsChecked property:
someCheckBox.IsChecked = !someCheckBox.IsChecked;
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