1
votes

I have a native control, written in C++ and using DirectX 11, that I would like to embed within a WPF application. Currently the control is hosted in a Windows Store app, and that works fine. I mention this in case Store App compatibility is important.

Based on Hosting Win32 Content in WPF, my understanding is that because WPF performs its own composition, and has a single window handle, the core complication is providing another window handle to the native control. Therefore, the solution is to add to the WPF page either a WindowsFormHost control or a control that derives from HwndHost and somehow associate the WPF control with the native control.

I went through the Hosting a Win32 Control in WPF walkthrough on MSDN. However, my control is not registered with the OS the way ListBox (the control used in the example) is. So, I cannot pass it as an argument to CreateWindowEx. How can I associate my own control? Do I create a WindowsFormsHost and call SetParent(myControlsHandle, windowsFormsHost.Handle)? Or do I create a WPF Border and set its Child property to a HwndHost instance?

There are other questions related to native controls in WPF (here and here, though the latter is about applications, not controls), but none address this question.

I looked into a different approach, where a WPF control shares a D3DImage with the native control, but that requires DirectX9EX, and my control is written in Dx11.

1

1 Answers