Skip to content
Robert B Colton edited this page Aug 12, 2016 · 1 revision

Screenshot

Provides a number of utilities and controls for working with XNA content in WPF. In the screenshot above, the document on the left uses DrawingSurface, and the tool window on the right uses GraphicsDeviceControl. Note that the GraphicsDeviceControl is clipped correctly against its parent ScrollViewer bounds.

Provides

  • GraphicsDeviceService service that implements XNA's IGraphicsDeviceService
  • ClippingHwndHost control that clips hosted Win32 content to a WPF control's bounds

The Xna module includes 2 alternatives for hosting XNA content in WPF:

  • DrawingSurface control that uses D3DImage as described here.
  • GraphicsDeviceControl control that implements Nick Gravelyn's technique for hosting WPF content using an HwndHost, described here

NuGet package

Dependencies

Usage

Both DrawingSurface and GraphicsDeviceControl provide similar APIs, but they are subtly different. DrawingSurface works seamlessly with WPF mouse and keyboard input, but GraphicsDeviceControl routes mouse input through its own set of methods (RaiseHwndLButtonDown etc.).

public class MyDrawingSurface : DrawingSurface
{
    protected override RaiseDraw(DrawEventArgs args)
    {
        args.GraphicsDevice.Clear(Color.LightGreen);
        base.RaiseDraw(args);
    }
}
public class MyGraphicsDeviceControl : GraphicsDeviceControl
{
    protected override void RaiseRenderXna(GraphicsDeviceEventArgs args)
    {
        args.GraphicsDevice.Clear(Color.LightGreen);
        base.RaiseRenderXna(args);
    }
}
Clone this wiki locally