/// <summary> /// Initialize the Spectrum virtual machine dependencies when the user control is loaded /// </summary> private void OnLoaded(object sender, RoutedEventArgs routedEventArgs) { Vm = DataContext as MachineViewModel; if (Vm == null) { return; } Vm.VmStateChanged += OnVmStateChanged; Vm.DisplayModeChanged += OnDisplayModeChanged; // --- Prepare the screen _displayPars = new ScreenConfiguration(Vm.ScreenConfiguration); _bitmap = new WriteableBitmap( _displayPars.ScreenWidth, _displayPars.ScreenLines, 96, 96, PixelFormats.Bgr32, null); Display.Source = _bitmap; Display.Width = _displayPars.ScreenWidth; Display.Height = _displayPars.ScreenLines; Display.Stretch = Stretch.Fill; // --- When the control is reloaded, resume playing the sound if (_isReloaded && Vm.VmState == VmState.Running) { Vm.SpectrumVm.BeeperProvider.PlaySound(); } // --- Register messages this control listens to Vm.VmScreenRefreshed += VmOnVmScreenRefreshed; // --- Now, the control is fully loaded and ready to work Vm.FastTapeMode = false; Vm.StartVmCommand.Execute(null); // --- Apply the current screen size // ReSharper disable once PossibleNullReferenceException OnDisplayModeChanged(this, EventArgs.Empty); }
/// <summary> /// Hides the constructor from external actors /// </summary> public DesignTimeAppViewModel() { MachineViewModel = new MachineViewModel(); }