Moving (dragging) HwndHost using mouse

469 Views Asked by At

Here's what I am trying to accomplish - To create an MDI application in WPF, which can host child web applications. I am using WPF webbrowser control to render web applications. WPF inherently doesn't seem to support MDI applications, so after a bit of searching, I found this project, which uses UI controls to simulate windows and manages them inside a WPF canvas. This approach seems to work reasonably well until I start adding webbrowser control object as an MDI child.

When I add webbrowser control as an MDI child, it always appears on top of other WPF elements including other MDI child controls (as shown below). From what I understand, webbrowser control always appears on top of any other WPF object except for window (and popup). Assuming that's true, I think I need to use actual WPF window to avoid overlapping issue.

enter image description here

The only solution i can think of right now is to wrap WPF window inside an HwndHost object and then add that as an MDI child. However it appears that a child window cannot have title bar. That means that i need to have a window that has a dummy title bar area (just like actual window title bar) and actual content area (which will show webbrowser control) as shown below (Red border is HwndHost object).

enter image description here

This approach seems to solve the overlapping issue. The next thing i need to try is to let users click on the dummy title bar and drag the MDI window inside the canvas element.

Questions -

  1. Is my understanding about WPF webbrowser control overlapping behavior right? If not, what am i missing?
  2. Is the second approach a step in right direction for accomplishing what i want? If yes, how do i implement the drag behavior for HwndHost?
  3. Is there any other alternate solution i can try?

Note:

  1. Although many consider MDI not an elegant solution, I do not have a choice. (We tried alternate solutions like tabbed windows/dockable windows, but were not well received)

  2. I am quite new to interop programming, and do not understand the concepts well. Please correct me if i am misunderstanding things.

Thanks!

0

There are 0 best solutions below