private void OnLoaded(object sender, RoutedEventArgs e) { if (_graphicsDeviceService == null) { DeviceService.StartD3D(Window.GetWindow(this)); // We use a render target, so the back buffer dimensions don't matter. _graphicsDeviceService = GraphicsDeviceService.AddRef(1, 1); _graphicsDeviceService.DeviceResetting += OnGraphicsDeviceServiceDeviceResetting; // Invoke the LoadContent event RaiseLoadContent(new GraphicsDeviceEventArgs(_graphicsDeviceService.GraphicsDevice)); EnsureRenderTarget(); CompositionTarget.Rendering += OnCompositionTargetRendering; _contentNeedsRefresh = true; } }
private void OnUnloaded(object sender, RoutedEventArgs e) { if (_graphicsDeviceService != null) { RemoveBackBufferReference(); CompositionTarget.Rendering -= OnCompositionTargetRendering; _graphicsDeviceService.DeviceResetting -= OnGraphicsDeviceServiceDeviceResetting; _graphicsDeviceService = null; DeviceService.EndD3D(); } }