'WPF airspace issue and WinForms IDesignHost
I'm trying to migrate portions of an app to WPF. One of the near-impossible parts is an IDesignerHost
(i.e., a Windows Forms Designer). So for that, I want to use a WPF window with a WindowsFormsHost
inside.
I've observed two issues in the default behavior:
- Windows Forms has strange colors when
WindowChrome
is used (see https://github.com/lepoco/wpfui/issues/141 and https://github.com/sourcechord/FluentWPF/issues/60) - any WPF control will clip if it partially overlays WinForms controls (obviously, this is the airspace issue)
Wrapping the WindowsFormsHost
in AirspaceDecorator
with the mode set to Redirect
, both of those disappear. Controls look right, and I can place WPF controls on top as well.
However! That setting seems to affect something related to… drag & drop, maybe?
If I use the IDesignerHost
's toolbox to create a new control, I can use the mouse to click and drag in order to set its size, then let go to have the new control be created.
But if I take an existing control, I cannot move it at all. I get an "unavailable" cursor, as though it's trying to initiate a drag & drop operation (with itself as the target). This does not happen if I remove the AirspaceDecorator
; moving controls does work, then.
(Incidentally, the behavior seems to be the same for AirspaceMode="Clip"
: I can show WPF controls on top, but I cannot move WinForms controls inside the IDesignerHost
.)
TL;DR: I need a way to host an IDesignerHost
inside a WPF window, and with the current AirspaceMode="Redirect"
approach, almost everything seems to work except actually moving controls in the designer around.
Edit:
From Seeking a Winforms System.ComponentModel.Design Design Surface BeginDrag/EndDrag Event Hook, I gathered that BehaviorService
is involved in the actual movement of controls. If I make a BeginDrag
event handler and set a breakpoint on that, then move a control,
- the event does fire,
- bizarrely, after resuming execution, the control has moved to its new position. (But if I don't set the breakpoint, I can't get the control to move, even if I let go of the mouse.)
So presumably, it's not that the designer doesn't want to perform the drag operation; it's that something else also wants to.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|