【发布时间】:2015-08-04 06:19:42
【问题描述】:
我所有的窗口共享同一个基类 WindowBase 。 我有
this.Activated += WindowBase_Activated;
和
void WindowBase_Activated(object sender, EventArgs e)
{
if (!_bActivating)
{
_bActivating = true;
activateAllWindows();
Activate();
_bActivating = false;
}
}
private void activateAllWindows()
{
Console.WriteLine("triggered");
foreach (Window window in Application.Current.Windows)
{
if (window.IsVisible && (window as WindowBase)._bActivating == false && window.WindowState==WindowState.Normal)
{
window.Activate();
}
}
}
它正在工作,但速度极慢。 但是,当应用程序启动时,我发现“已触发”打印或多或少 100 次。
我要做的就是将所有窗口都放在前面,同时将我从任务栏单击的窗口堆叠到顶部。 我该如何改进?
附:我不会把我的窗户从最小化。就在前面。 我可以在 Qt 中做到这一点,因为 QWidget 有一个名为 stackUnder 的函数(作为窗口)
【问题讨论】:
标签: wpf window activation