可以将文章内容翻译成中文,广告屏蔽插件可能会导致该功能失效(如失效,请关闭广告屏蔽插件后再试):
问题:
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;
- Request UiAccess="True"
- 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.
- 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; }