WPF Always On Top

匿名 (未验证) 提交于 2019-12-03 02:44:02

问题:

Is it possible to make a window stay always on top even when other application is running on Fullscreen? I'm using right now TopMost = true but when other application is running on fullscreen mine becomes invisible. It's WindowStyle = None window by the way.

Edit: And do not let other window minimalize ofcourse

回答1:

This won't work 100% of the time, but it will improve the situation somewhat. You can set Topmost = true in the handler for the Window.Deactivated event:

private void Window_Deactivated(object sender, EventArgs e) {     Window window = (Window)sender;     window.Topmost = true; } 

The Deactivated event will be called whenever your application loses focus (often when another application requests to be Topmost) and so this will reset your application on top after this.



回答2:

Try this solution from MSDN, it should work for you. In the Window Activated Event add the following code:

this.Width = System.Windows.SystemParameters.PrimaryScreenWidth; this.Height = System.Windows.SystemParameters.PrimaryScreenHeight; this.Topmost = true; this.Top = 0; this.Left=0; 

in DeActivated Event add the following code

this.Topmost = true; this.Activate(); 

Original post from MSDN



回答3:

If you want your application to stay on top of EVERYTHING (including the start interface in Windows 8, previously known as "Metro"), then you can specify UiAccess="True" in your manifest file. This is typically used by accessibility applications such as onscreen keyboards.

From memory you need to do 3 things;

  1. Request UiAccess="True"
  2. Sign your application's exe file with a recognised certificate. I obtained a free code signing certificate from Certum as my project is Open Source.
  3. Install your application to a "Trusted Location", which in my case was the program files directory. There is no official definition of "Trusted Location" that I could find.


回答4:

I had a main window that I wanted to keep on top of everything (if the user checked "always on top".
This worked for me. Hope this helps someone.

        // If we want main to stay on top, we set the rest of the menus to Not be top          if (mnuViewMainWindowAlwaysOnTopo.IsChecked)         {             this.Topmost = true;             foreach (Window window in Application.Current.Windows)             {                 // Don't change for main window                 if (window.GetType().Name != this.GetType().Name)                 {                     window.Topmost = false;                 }             }         }         else         {             this.Topmost = false;         } 


文章来源: WPF Always On Top
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!