WPF input Interop over DirectX Airspace

I've seen that the Airspace regions constraints have been a concern for some folks interested in using DirectX with their WPF applications. Based on this, here is a follow-up to an earlier sample I posted, this time using Layered windows to intercept input, allowing for the provision of rich WPF context menus, tooltips, and traditional mouse actions over the airspace of an interop region. It is pretty much the same as before, with one major change - the introduction of an "AirspaceOverlay" decorator.

 This decorator wraps around your interop content, and accepts an "OverlayChild" which is presented in a layered window over the content in the AirspaceOverlay control. In the example below, I used a canvas with a tooltip and some code-behind to also demonstrate a context menu. Here's a code snippet of the usage:



        <Canvas ToolTip = "A tooltip over a DirectX surface" Background="#01000000" Name="Overlay" />


<!--Your Non-WPF Airspace Interop content goes here-->



Known considerations:

  • Embedding of AirspaceOverlay in a Viewbox - due to region sizing issues, overlay placeent does not work correctly.
  • Hit testing within the transparent window will not occur on fully transparent regions, but will continue to propagate down to the interop surface. On the flip side, partially opaque regions will intercept input, preventing it from being recieved on the interop layer. This input handling behavior can be tweaked from the Win32 API's.
  • Focus will by default switch between the parent and layered child window. I return focus on mouse behavior to the parent in this implementation.
  • This sample is targeted to rectangular regions. By applying a custom shape consistent with the region below, irregular airspace regions can be overlaid with little additional effort.

I hope this helps some food for thought for folks looking at similar interop scenarios. Ok, have fun with the code, and feel free to send in questions.

WPF-DX Interop - Part 2 .zip