I have a control that contains a Togglebutton and a Popup. When the ToggleButton is clicked on, the popup appears. When the ToggleButton is unchecked, the popup should close. Additionally, clicking away from the popup should cause it to close, and cause the Togglebutton to uncheck.
I've set this up by setting the StaysOpen property of the Popup to false, and setting the IsChecked property of the toggle button to be two-way bound to the IsOpen property of the Popup.
All is well, apart from one case - with the button checked and the popup open, clicking the button does not cause the popup to close, or the button to return to unchecked.
I believe this must be because clicking the button causes the StaysOpen logic of the Popup to set the Popup's IsOpen property to false. In turn, this sets the Togglebutton to unchecked. This must happen before my click on the button is processed - so the click re-checks the button, ie a race condition.
Any idea how I can get the behaviour I want?
ToggleButton
, but you want to click on everything else – Huntsman