locked
How to Hide the Popup window when move the focus to another window? RRS feed

  • Question

  • Hi All,

    In my custom control , i have popup window for perform some operation. Now my problem is after open the Popup window if i am pressing the Alt + Tab , the PopUp does not close. It still opened in another Window. I need to close the Popup window when the focus moved to the another window.

    How can i resolve this problem from my side. Please give your suggestion on this.

    Thanks,

    Sowndaiyan
    Thursday, March 17, 2016 10:14 AM

Answers

  • Set the Popup property IsOpen to false.

    Lloyd Sheen

    • Proposed as answer by noorbakhsh Thursday, March 17, 2016 3:28 PM
    • Marked as answer by Xavier Xie-MSFT Tuesday, March 29, 2016 3:24 AM
    Thursday, March 17, 2016 1:19 PM
  • >>How can i resolve this problem from my side. Please give your suggestion on this.

    You could get a reference to the parent window in your custom control using the Window.GetWindow method and set the IsOpen property of the Popup control to false when the window's Deactivated event occurs, e.g.:

    public class YourCustomControl : Control
        {
            public YourCustomControl()
            {
                this.Loaded += (s, e) => 
                {
                    Window parentWindow = Window.GetWindow(this);
                    parentWindow.Deactivated += (ss, ee) =>
                    {
                        if (popup != null)
                            popup.IsOpen = false;
                    };
                };
            }
    
            Popup popup;
            public override void OnApplyTemplate()
            {
                base.OnApplyTemplate();
                popup = Template.FindName("popup", this) as Popup;
            }
        }
    

    ControlTemplate:

    ...
    <Popup x:Name="popup">
    ...

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    Thursday, March 17, 2016 9:51 PM

All replies

  • Set the Popup property IsOpen to false.

    Lloyd Sheen

    • Proposed as answer by noorbakhsh Thursday, March 17, 2016 3:28 PM
    • Marked as answer by Xavier Xie-MSFT Tuesday, March 29, 2016 3:24 AM
    Thursday, March 17, 2016 1:19 PM
  • >>How can i resolve this problem from my side. Please give your suggestion on this.

    You could get a reference to the parent window in your custom control using the Window.GetWindow method and set the IsOpen property of the Popup control to false when the window's Deactivated event occurs, e.g.:

    public class YourCustomControl : Control
        {
            public YourCustomControl()
            {
                this.Loaded += (s, e) => 
                {
                    Window parentWindow = Window.GetWindow(this);
                    parentWindow.Deactivated += (ss, ee) =>
                    {
                        if (popup != null)
                            popup.IsOpen = false;
                    };
                };
            }
    
            Popup popup;
            public override void OnApplyTemplate()
            {
                base.OnApplyTemplate();
                popup = Template.FindName("popup", this) as Popup;
            }
        }
    

    ControlTemplate:

    ...
    <Popup x:Name="popup">
    ...

    Hope that helps.

    Please remember to close your threads by marking helpful posts as answer and then start a new thread if you have a new question. Please don't ask several questions in the same thread.

    Thursday, March 17, 2016 9:51 PM