Popup always stays on top

前端 未结 7 1850
傲寒
傲寒 2020-12-05 15:20

I\'ve WPF application which has one Main window on which I\'m opening a Popup window. The problem I\'m facing is the Popup window always stays on top. If I open some other a

相关标签:
7条回答
  • 2020-12-05 15:48

    Popups do - as far as i know - not suppot such a behavior, their intended usage is for ComboxBox-dropdowns and the like as far as i can tell. To realize something like that you can use a normal Window and set its Owner to the main window on which it should be dependent. This will cause the popup-window to stay on top of its owner & to minimize together with the owner.

    e.g.

    public class ChildWindow: Window
    {
        public ChildWindow(Window owner)
        {
            this.Owner = owner;
        }
    }
    
    var popup = new ChildWindow(mainWindow);
    popup.Show();
    

    (Windows cannot be re-opened once closed, so to reuse a window you just have to Hide() it when the user tries to close it (handle Closing event and cancel using event args))

    0 讨论(0)
提交回复
热议问题