Пример #1
0
        protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
        {
            base.OnRenderSizeChanged(sizeInfo);

            if (IsInDesignMode)
            {
                return;
            }

            _logger.Information("Render size changed to {Size}", sizeInfo.NewSize);

            // sometimes OnRenderSizeChanged happens before OnLoaded.
            Start();
            ResetBackBufferReference();

            if (GraphicsDevice != null)
            {
                _viewModel.OnSizeChanged((int)sizeInfo.NewSize.Width, (int)sizeInfo.NewSize.Height);
            }
        }
Пример #2
0
        private void Start()
        {
            if (_isInitialized)
            {
                return;
            }

            if (Application.Current.MainWindow == null)
            {
                throw new InvalidOperationException("The application must have a MainWindow");
            }

            Application.Current.MainWindow.Closing         += (sender, args) => _viewModel?.OnExiting(this, EventArgs.Empty);
            Application.Current.MainWindow.ContentRendered += (sender, args) =>
            {
                if (_isFirstLoad)
                {
                    var width  = (int)ActualWidth;
                    var height = (int)ActualHeight;
                    _graphicsDeviceService.StartDirect3D(Application.Current.MainWindow, width, height);
                    _viewModel?.Initialize();
                    _viewModel?.LoadContent();
                    _viewModel?.OnSizeChanged(width, height);
                    _isFirstLoad = false;
                }
            };

            _direct3DImage = new D3DImage();

            AddChild(new Image {
                Source = _direct3DImage, Stretch = Stretch.None
            });

            _renderTarget = CreateRenderTarget();
            CompositionTarget.Rendering += OnRender;
            _stopwatch.Start();
            _isInitialized = true;
        }