void XnaWindowHost_Loaded(object sender, RoutedEventArgs e) { // If we don't yet have a GraphicsDeviceService reference, we must add one for this control if (graphicsService == null) { graphicsService = GraphicsDeviceService.AddRef(hWnd, (int)ActualWidth, (int)ActualHeight); services.AddService<IGraphicsDeviceService>(graphicsService); // Invoke the LoadContent event if (LoadContent != null) LoadContent(this, new GraphicsDeviceEventArgs(graphicsService.GraphicsDevice)); } }
protected override void Dispose(bool disposing) { // Release our reference to the GraphicsDeviceService if we have one if (graphicsService != null) { graphicsService.Release(disposing); graphicsService = null; } // Unhook the Rendering event so we no longer attempt to draw CompositionTarget.Rendering -= CompositionTarget_Rendering; base.Dispose(disposing); }