public SavePopupViewModel(string message, Action toConfirm, bool hasCancelButton) { Message = message; HasCancelButton = hasCancelButton; hardReferences.Add(toConfirm); // we have to keep a hard reference to the action passed to Register, // otherwise it's garbage collected (because it uses closures). // see https://stackoverflow.com/questions/25730530/bug-in-weakaction-in-case-of-closure-action Action saveCommandExecute = () => { RequestSaveToGameScreenMessage.Send(MessengerInstance); toConfirm(); CloseSavePopupMessage.Send(MessengerInstance); }; hardReferences.Add(saveCommandExecute); SaveCommand = new RelayCommand(saveCommandExecute); Action confirmCommandExecute = () => { toConfirm(); CloseSavePopupMessage.Send(MessengerInstance); }; hardReferences.Add(confirmCommandExecute); ConfirmCommand = new RelayCommand(confirmCommandExecute); CancelCommand = new RelayCommand(() => CloseSavePopupMessage.Send(MessengerInstance)); }
private void InitMessageHandlers() { // Receive any move and update the primary game's state. CommitMoveMessage.Register(MessengerInstance, this, action => UpdateGame(action, PrimaryGame)); // These message handlers stay irrespective of the ActiveMode UndoMessage.Register(MessengerInstance, this, () => Undo(ModeSpecificGame())); RedoMessage.Register(MessengerInstance, this, () => Redo(ModeSpecificGame())); SwitchGameViewModeMessage.Register(MessengerInstance, this, mode => ActiveMode = mode); PauseGameMessage.Register(MessengerInstance, this, () => _aiLoopCanRun = false); // someone requested that the current state of the game be saved RequestSaveToGameScreenMessage.Register( MessengerInstance, this, () => { SaveGameMessage.Send(MessengerInstance, (GameId, PrimaryGame.Memento)); PrimaryNeedsSaving = false; });