K T
K T

Reputation: 199

PopUp window is still visible on screen if the MainWindow is out of focus in WPF

I have a PopUp window with a popup control.There is a main window from which this PopUp is displayed. PopUp displays data after processing the query which takes time.So while the data in the PopUp is processing,if I maximise other windows then the PopUp is displayed on the other windows as well.

I have made MainWindow owner of the PopUp window in PopUpWindow.xaml.cs as:

this.Owner = Application.Current.MainWindow;

and I have set "StaysOpen" property of PopUp Window to false.But still issue persists.How to stop PopUp from displaying on other window,if other windows are maximised.

Upvotes: 4

Views: 1876

Answers (1)

voyce
voyce

Reputation: 677

You can explicitly close the popup when its owner window is deactivated, i.e. when another window gets the focus and comes to the top, using the Deactivated event:

    window.Deactivated += 
        (sender, args) => {
            thePopup.IsOpen = false;
        };

You might also want to capture the IsOpen state and restore it when the window is Activated.

Upvotes: 2

Related Questions