She*_*dan 44
这不会在100%的时间内起作用,但它会在某种程度上改善这种情况.您可以Topmost = true在Window.Deactivated事件的处理程序中设置:
private void Window_Deactivated(object sender, EventArgs e)
{
Window window = (Window)sender;
window.Topmost = true;
}
Run Code Online (Sandbox Code Playgroud)
Deactivated只要您的应用程序失去焦点(通常在另一个应用程序请求时Topmost),就会调用该事件,因此这将在此之后重置您的应用程序.
Moh*_*dil 12
从MSDN尝试此解决方案,它应该适合您.在Window Activated Event添加以下代码:
this.Width = System.Windows.SystemParameters.PrimaryScreenWidth;
this.Height = System.Windows.SystemParameters.PrimaryScreenHeight;
this.Topmost = true;
this.Top = 0;
this.Left=0;
Run Code Online (Sandbox Code Playgroud)
在DeActivated Event添加以下代码
this.Topmost = true;
this.Activate();
Run Code Online (Sandbox Code Playgroud)
上面对我来说没有一个解决方案有效,所以这就是我最终要做的。它对我来说非常有效。
基本上,要使其保持在顶部,您只需设置失去焦点事件以使其回到顶部。
XAML:
PreviewLostKeyboardFocus="Window_PreviewLostKeyboardFocus"
Run Code Online (Sandbox Code Playgroud)
背后的代码:
private void Window_PreviewLostKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
Window window = (Window)sender;
window.Topmost = true;
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
56434 次 |
| 最近记录: |