我正在使用Windowsformhost派生的Ipaddress控件.但是当我向下滚动我的窗口小部件时,它漂浮在窗口小部件外部,任何解决方案都会令人赞赏. [英] I Am Using Ipaddress Control Derived From Windowsformhost. But When I Scroll Down My Widget It Is Floating Outside Of Widget.Any Solution Will Be Appreciate.
问题描述
xmlns:ipBox ="clr-namespace:IPAddressControlLib; assembly = IPAddressControlLib"
xmlns:ipBox="clr-namespace:IPAddressControlLib;assembly=IPAddressControlLib"
<local:WindowsFormsHostExtended Grid.Column="1" Grid.Row="1" Margin="40,15,3,0" Width="150" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" ScrollViewer.HorizontalScrollBarVisibility="Auto" ScrollViewer.VerticalScrollBarVisibility="Auto">
<ipBox:IPAddressControl x:Name="IPAddress" TextChanged="IPAddress_TextChanged" />
</local:WindowsFormsHostExtended>
推荐答案
这是WPF/WinForms互操作的一个众所周知的问题,通常称为空域"问题.添加到WPF窗口的WinForms控件有严格的限制:
This is a well-known problem with WPF/WinForms interop, often referred to as the "airspace" issue. WinForms controls added to a WPF window have severe limitations:
- HwndHost不能旋转,缩放,倾斜或受Transform影响.
- HwndHost不支持不透明度"属性(alpha混合).如果HwndHost内部的内容执行包含alpha信息的System.Drawing操作,这本身并不违反,但是HwndHost整体上仅支持Opacity = 1.0(100%).
- HwndHost将在同一顶级窗口中显示在其他WPF元素的顶部.但是,ToolTip或ContextMenu生成的菜单是一个单独的顶级窗口,因此在HwndHost上将正常运行.
- HwndHost不尊重其父UIElement的剪切区域.如果您尝试将HwndHost类放在滚动区域或Canvas中,则可能会出现问题.
- 当鼠标悬停在HwndHost上时,您的应用程序不会收到WPF鼠标事件,并且WPF的值属性IsMouseOver将为false.
- 虽然HwndHost具有键盘焦点,但是您的应用程序将不会接收WPF键盘事件,并且WPF属性IsKeyboardFocusWithin的值将为false.
- 当焦点为在HwndHost中并更改为HwndHost内部的另一个控件时,您的应用程序将不会收到WPF事件GotFocus或LostFocus.
- 相关的笔属性和事件是相似的,并且当笔在HwndHost上时不会报告信息.
- HwndHost cannot be rotated, scaled, skewed, or otherwise affected by a Transform.
- HwndHost does not support the Opacity property (alpha blending). If content inside the HwndHost performs System.Drawing operations that include alpha information, that is itself not a violation, but the HwndHost as a whole only supports Opacity = 1.0 (100%).
- HwndHost will appear on top of other WPF elements in the same top-level window. However, a ToolTip or ContextMenu generated menu is a separate top-level window, and so will behave correctly with HwndHost.
- HwndHost does not respect the clipping region of its parent UIElement. This is potentially an issue if you attempt to put an HwndHost class inside a scrolling region or Canvas.
- While the mouse is over the HwndHost, your application does not receive WPF mouse events, and the value of the WPF property IsMouseOver will be false.
- While the HwndHost has keyboard focus, your application will not receive WPF keyboard events and the value of the WPF property IsKeyboardFocusWithin will be false.
- When focus is within the HwndHost and changes to another control inside the HwndHost, your application will not receive the WPF events GotFocus or LostFocus.
- Related stylus properties and events are analogous, and do not report information while the stylus is over HwndHost.
计划在.NET 4.5中修复此问题;不幸的是,相关属性已在最终版本中删除:
缓解WPF应用程序中的空域问题 [ ^ ]
有一个UserVoice建议将这些beta功能重新带回,但被拒绝了:
带回HwndHost.IsRedirected和CompositionMode [克服WPF中的Interop空域问题 [
There were plans to fix this in .NET 4.5; unfortunately, the relevant properties were dropped in the final release:
Mitigating Airspace Issues In WPF Applications[^]
There was a UserVoice suggestion to bring these beta features back, but that was declined:
Bring back the HwndHost.IsRedirected and CompositionMode[^]
There are various workarounds which attempt to solve the problem (eg: Over-coming the Interop Airspace Issue in WPF[^]). However, there''s no guarantee that they''ll work as you need them to.
The best solution is probably to try to recreate the control in WPF.
这篇关于我正在使用Windowsformhost派生的Ipaddress控件.但是当我向下滚动我的窗口小部件时,它漂浮在窗口小部件外部,任何解决方案都会令人赞赏.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!