Welcome to MSDN Blogs Sign in | Join | Help

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:

<MDXControl:AirspaceOverlay>

    <MDXControl:AirspaceOverlay.OverlayChild>

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

    </MDXControl:AirspaceOverlay.OverlayChild>

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

</MDXControl:AirspaceOverlay>

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.

Published Tuesday, July 31, 2007 1:50 AM by pantal
Filed under: , , , ,

Attachment(s): WPF-DX Interop - Part 2 .zip

Comments

# re: WPF input Interop over DirectX Airspace

Wednesday, February 13, 2008 2:27 PM by jamiebriant

On my x64 system, it leaks memory like a sieve. Appears to be down in the unmanaged WPF code - managed memory is steady at 2mb. Haven't tried it on a 32bit system. Any ideas?

# re: WPF input Interop over DirectX Airspace

Thursday, February 14, 2008 12:51 AM by pantal

Hmm. Could you email(from the email link on side) me with details/repro on the 64 bit issue you are investigating?

Thanks!

# re: WPF input Interop over DirectX Airspace

Tuesday, February 19, 2008 11:33 PM by pantal

I was able to repro the issue Jamie described. The app was erroneoously creating a shader object each render cycle, without explicitly disposing previous due to a caching logic bug.

BTW: In theory, the unmanaged shader resources should eventually get released when the managed objects are disposed via GC, but there is also an explicit api for release of the unmanaged resources.

In ShaderRenderer.cs, Line 34 replace:

reloadTexture = false;

with:

reloadShader = false;

# re: WPF input Interop over DirectX Airspace

Tuesday, July 15, 2008 8:55 AM by OverMalo

Hi.

Can i use this form to put WPF Button, WPF Windows or some WPF controls over directx surface... ¿?.

Thanks you.

Anonymous comments are disabled
 
Page view tracker