What you trying to do might not make for the best user experience because you're going to have to implement a delay prior to processing a user's attempt to check the box.
Why?
Well, if you double click the checkbox, you want nothing to happen with the checkbox, you just want to pass control up to the button. That's totally understandable.
But what happens if you simply click the checkbox? At the moment you release the mouse button, you are going to expect the check mark to appear. But the system can't yet know that you don't plan to click again. So, it has to wait through the DoubleClickTime to determine that you in fact never double-clicked.
You have to weigh which is worse: delay when checking the checkbox vs. flicker when double-clicking the checkbox.
If you decide to go with the delay, you'll need to implement it yourself. Here's a basic procedure that should work:
- Create a handler for CheckBox.PreviewMouseDown. Within this handler, disable the CheckBox and start a DispatcherTimer with an interval of DoubleClickTime.
- Meanwhile, create a handler for Button.MouseDoubleClick that sets a field,
_hasDoubleClicked
, to true.
- When the timer goes off, enable the checkbox, and if
_hasDoubleClicked
is false, toggle the IsChecked
of the checkbox. Also, set _hasDoubleClick = false
.
As you can see this is not pretty. You might want to ask yourself if there is another way to achieve your goal with a different design. Do you need to use double-click in the first place?