How to make a WPF window be on top of all other windows of my app (not system wide)?

后端 未结 19 3029
南笙
南笙 2020-12-14 05:42

I want my window to be on top of all other windows in my application only. If I set the TopMost property of a window, it becomes on top of all windows of al

19条回答
  •  孤城傲影
    2020-12-14 05:52

    Here's a way to do it: make your "topmost" window subscribe to your other windows GotFocus and LostFocus events and use the following as the event handlers:

    class TopMostWindow
    {
        void OtherWindow_LostFocus(object sender, EventArgs e)
        {
            this.Topmost = false;
        }
    
        void OtherWindow_GotFocus(object sender, EventArgs e)
        {
            this.Topmost = true;
        }
    }
    

提交回复
热议问题