WPF 窗体在Alt+Tab中隐藏

问题: 

     近段时间由于项目上的需求,需要在WPF中使用COM组件,并且由于软件界面设计等等原因,需要将部分控件显示在COM组件之上,由于WindowsFormsHost的一些原因,导致继承在WPF中的Winform控件或者COM组件总是置于顶层,覆盖其他WPF元素。

  为了解决样式布局问题,这里我采用了父子窗体方式实现,使用定位方式将子窗体置于父窗体的合适位置:

  

  这样,解决了设计上的问题,但是新的问题随之又来了:使用Alt+Tab、或者任务管理器等等可以在Taskbar中看到多个窗体缩略图,如图:

      

 

  这样十分的影响用户体验,并且软件的其他窗口也可能被用户关掉,降低软件的用户体验。

如何解决: 

  我们只需要将需要隐藏Alt+Tab窗体的  ShowInTaskbar 属性设置为 False,并且把该子窗体的Owner属性设置为对应的父窗体引用 即可

<Window x:Class="Test.RevealModelFunctionMenu"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        mc:Ignorable="d"
        WindowStyle="None"
        BorderBrush="Transparent" 
        BorderThickness="0"
      ShowInTaskbar="False"
        AllowsTransparency="True"
        Background="Transparent"
        Title="FunctionMenu" Height="165" Width="420">

 

   来一张隐藏后的效果图:

    

PS:

 1. WindowsFormsHost is always the most top from WPF element  

    

According to MSDN (Layout Considerations for the WindowsFormsHost Element)

 A hosted Windows Forms control is drawn in a separate HWND, so it is always drawn on top of WPF elements.

This is a design limitation

   2.   WindowsFormsHost 的布局注意事项

posted @ 2018-01-10 21:41  betterme  阅读(624)  评论(0编辑  收藏  举报