在WPF中使用WindowsFormsHost带来的问题及解决方案
2016-02-23 09:44
453 查看
首先明确指出的是你要解决的问题没有可行的解决方案,然后你还有兴趣的话,可以继续往下看。
继续往下看的程序员都是好程序员!!!
本人开发环境:VS2013 && .NET 4.5.1问题:在wpf中嵌入WindowsFormsHost后,WINFORM的元素都在最顶层,所以要在TABCONTROL中切来切去的时候,会发现不管咋切winform的元素都处于显示状态,就算当你想用SCROLLVIEWER包一下,对不起,当你使用滚动条的时候,winform元素甚至连你的滚动条都 遮挡了。
对于此问题,无解!无解!无解!
首先看一下MS的说法:
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
意思就是说,WINFORM元素一直都在最顶层,这是设计的限制。
一直到.NET FRAMEWORK 4.0时候都是这个状况。
再看看MS对这个问题的尝试
A year later, things have changed a bit with .NET 4.5. For those who stumbled upon this, much as I did, here is a more updated excerpt from Walkthrough: Arranging Windows Forms Controls in WPF on MSDN: By default, visible WindowsFormsHost elements are always drawn on top of other WPF elements, and they are unaffected by z-order. To enable z-ordering, set the IsRedirected property of the WindowsFormsHost to true and the CompositionMode property to Full or OutputOnly.
All you need to do, when using .NET 4.5, is add the following attributes to your WindowsFormsHost element IsRedirected="True" and CompositionMode="Full" or CompositionMode="OutputOnly".
在.net 4.5,微软尝试解决这个问题,就是添加几个属性的事。这是个大坑,也不知道到底解决的如何,此功能仅限于4.5 BETA版,在正式版里,又没有这两个属性了。
(微软自己都解决不了的问题,真尴尬!!!)
再看看MS的新说法
1.3.10 Windows Presentation Foundation (WPF) 1.3.10.1 HwndHost feature has been removed from WPF in the .NET Framework 4.5 Beta The .NET Framework 4.5 Developer Preview included a WPF HwndHost redirection feature. However, this feature had several known issues and has been removed from the .NET Framework 4.5 Beta. It will not be included in any future releases. To resolve this issue: No workaround is available.
意思是说:
1.3.10WindowsPresentationFoundation(WPF)1.3.10.1HwndHost特性已被删除从WPF。净框架4.5Beta。净框架4.5开发人员预览版包括一个WPFHwndHost重定向功能。然而,这个功能有几个已知问题和已被删除。净框架4.5Beta。它将不会被包括在任何未来的版本。解决这一问题:没有可用的解决方法。
总之就是无解,无解,无解!!!
以下是一些链接,也是说的相同问题
https://social.msdn.microsoft.com/Forums/vstudio/en-US/8183e167-abfc-49c2-9a0c-05b5ddf2bf30/windowsformshost-always-topmost?forum=wpfhttps://social.msdn.microsoft.com/Forums/vstudio/en-US/8183e167-abfc-49c2-9a0c-05b5ddf2bf30/windowsformshost-always-topmost?forum=wpf
http://dolinked.com/questions/1275873/windowsformshost-is-always-the-most-top-from-wpf-element
https://msdn.microsoft.com/zh-cn/library/ms752027(v=vs.110).aspx
相关文章推荐
- iOS图标(AppIcon)与启动图(LaunchImage)
- Android 集成新浪微博分享及授权 (上)
- 使用SpringSecurity3用户验证(异常信息,验证码)
- 怎样克服效率低
- popup_layer jquery 弹出层使用,说明,详解
- 如何选择Html.RenderPartial和Html.RenderAction
- 分布式ID生成方法
- stress压力测试
- 使用Maven搭建Hadoop开发环境
- 2016-02-22 监听键盘 隐藏bar
- Python lib
- weiapi2.2 HelpPage自动生成接口说明文档和接口测试功能
- PrintWriter 和 Scanner 类的组合使用
- SCCM 2012 R2系列
- Apple Watch与iPhone数据通信———— Watch Connectivity
- 433和2.4G无线通信比较
- 学习Discuz! X3.2记录:又一个幻灯的代码
- vim快捷键
- writev/readv
- JQuery在iframe中实现 点击后选中当前栏目的样式