Reputation: 139
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();
Upvotes: 3
Views: 956
Reputation: 169190
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;
Upvotes: 5