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 的布局注意事项

转载于:https://www.cnblogs.com/u-drive/p/8260783.html

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值