Example #1
0
        protected override void Dispose(bool disposing)
        {
            // Release our reference to the GraphicsDeviceService if we have one
            if (_graphicsService != null)
            {
                _graphicsService.Release(disposing);
                _graphicsService = null;
            }

            SizeChanged -= OnXnaWindowHostSizeChanged;
            Loaded -= OnXnaWindowHostLoaded;

            base.Dispose(disposing);
        }
Example #2
0
        private void OnXnaWindowHostLoaded(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((int) ActualWidth, (int) ActualHeight);

                // Invoke the LoadContent event
                RaiseLoadContent(new GraphicsDeviceEventArgs(_graphicsService.GraphicsDevice));
            }
        }
Example #3
0
        private void OnUnloaded(object sender, RoutedEventArgs e)
        {
            if (_graphicsDeviceService != null)
            {
                RemoveBackBufferReference();

                CompositionTarget.Rendering -= OnCompositionTargetRendering;

                _graphicsDeviceService.DeviceResetting -= OnGraphicsDeviceServiceDeviceResetting;
                _graphicsDeviceService = null;
            }
        }
Example #4
0
        private void OnLoaded(object sender, RoutedEventArgs e)
        {
            if (_graphicsDeviceService == null)
            {
                // 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;
            }
        }
Example #5
0
        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 all events.
            CompositionTarget.Rendering -= OnCompositionTargetRendering;
            if (Application.Current != null)
            {
                Application.Current.Activated -= OnApplicationActivated;
                Application.Current.Deactivated -= OnApplicationDeactivated;
            }
            SizeChanged -= OnXnaWindowHostSizeChanged;
            Loaded -= OnXnaWindowHostLoaded;

            base.Dispose(disposing);
        }