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

后端 未结 19 2751
南笙
南笙 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 06:13

    Instead you can use a Popup that will be TopMost always, decorate it similar to a Window and to attach it completely with your Application handle the LocationChanged event of your main Window and set IsOpen property of Popup to false.

    Edit:

    I hope you want something like this:

        Window1 window;
    
        private void Button_Click(object sender, RoutedEventArgs e)
        {
            window = new Window1();
            window.WindowStartupLocation = WindowStartupLocation.CenterScreen;
            window.Topmost = true;
            this.LocationChanged+=OnLocationchanged;
            window.Show();
        }
         
        private void OnLocationchanged(object sender, EventArgs e)
        {
              if(window!=null)
                  window.Close();
        }
    

    Hope it helps!!!

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