Sekar Thangavel
Sekar Thangavel

Reputation: 41

Outside mouse click of the popup control WPF

We have requirement to show popup. On click outside of the control it automatically closed .For example click any button that button action triggers . The requirement popup should work like combo box . When click out of bound it closes the dropdown and any other would not trigger. I do that using mouse capture and works for the button click . But on click the tab control selection is happens .How to stop the mouse interception.

Thanks Sekar

Upvotes: 3

Views: 1551

Answers (1)

Ignatius
Ignatius

Reputation: 1177

To make the popup close when you click outside it, you can set your popup's StaysOpen property to false.

As for stopping the mouse click from triggering on other controls, perhaps you can use this trick: When your popup is opened, temporarily set the IsHitTestVisible property of your window to false. And when it is closed, set it back to true, for example:

<Popup x:Name="popup1" StaysOpen="False" Opened="popup1_Opened" Closed="popup1_Closed">

And the code behind:

private void popup1_Opened(object sender, EventArgs e)
{
    window1.IsHitTestVisible = false;
}

private void popup1_Closed(object sender, EventArgs e)
{
    window1.IsHitTestVisible = true;
}

Upvotes: 0

Related Questions