0

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:

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,

  1. the event does fire,
  2. 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.

Sören Kuklau
  • 19,454
  • 7
  • 52
  • 86
  • 1
    Winforms and WPF have to totally different approach to data binding and design method... is it possible to consider to re-write the winform into a WPF user control? – Marco Beninca May 13 '22 at 10:03
  • Yes, the poor view-model separation is one of the reasons I want to migrate away from WinForms. ;-) I don't believe rewriting `IDesignerHost` in WPF is feasible. Even if it were, it's only the tip of the iceberg. – Sören Kuklau May 13 '22 at 10:10
  • Well designer in WPF is your xaml, no names for UI elements, Binding support in xaml are just a few to name. I can't think of anything that would be difficult in WinForms that can't be done in WPF. Maybe you are approaching it from WinForms view, which is to create controls yourself, WPF you have base controls and then use behaviours, attached properties etc. Styles alone will decrease amount of work needed. Maybe you should ask more specific question about how to convert what you have into WPF? – XAMlMAX May 13 '22 at 21:16

0 Answers0