Click here to Skip to main content
15,892,674 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
xmlns:ipBox="clr-namespace:IPAddressControlLib;assembly=IPAddressControlLib"
XML
<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>
Posted

1 solution

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 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.



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.
 
Share this answer
 
Comments
Member 11892033 26-Aug-15 7:09am    
Thanks Richard for the reply.
I will try to implement new one in WPF instead of finding solution to earlier.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900