【问题标题】:WPF Bring window to frontWPF 将窗口置于前面
【发布时间】:2012-10-08 05:46:01
【问题描述】:

当通过 DragMove 将窗口拖动到特定区域时,我想在该区域显示半透明窗口覆盖。

显示窗口工作正常,但它总是出现在我拖动的窗口的顶部。

在显示叠加层后,我尝试了各种方法,例如 .focus/.activate,但都不起作用。

每个窗口都有WindowStyle="None" Topmost="True" ShowInTaskbar="False",覆盖窗口甚至有IsHitTestVisible="False" Focusable="False"。不过,当它的可见性打开时,叠加层仍然会获得焦点。

【问题讨论】:

    标签: wpf window visibility


    【解决方案1】:

    我发现唯一可行的方法是隐藏我的主窗口,然后再次显示它。不过,我不希望它闪烁,所以我在执行此操作时禁用了调度程序。这最终工作得很好。我在网上找不到任何类似的问题,所以我想我会发布这个来帮助下一个人。

    private void showOverlay()
    {
      //show the docking window
      _overlayWindow.Visibility = Visibility.Visible;
    
      //problem here will be that the overlay window will be on top of main
      //this.focus   this.activate +other efforts did not work to bring main back on top
    
      //only thing i could find that would bring the main win on top is to hide/show it again.
      //i wrap this hide/show in a disabled dispatcher block so that the window never really gets hidden on screen
    
      using (var d = Dispatcher.DisableProcessing())
      {
        this.Visibility = Visibility.Hidden;
        this.Visibility = Visibility.Visible;
      }
    }
    

    【讨论】:

    • 如果您有更好的解决方案,请随时发布其他解决方案。
    猜你喜欢
    • 2011-11-04
    • 1970-01-01
    • 2010-09-20
    • 2017-12-02
    • 1970-01-01
    • 2011-10-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多