I am developing a Windows Store apps game using WinRT Caliburn.Micro, and I am relying on the navigation framework.
I have view models for the game setup (define players) and the actual game. When navigating from the setup to the game, I want to pass the collection of players to the game view model. How can I do this?
Schematically, my view models currently look like this:
public class SetupGameViewModel : NavigationViewModelBase
{
public SetupGameViewModel(INavigationService ns) : base(ns) { }
public IObservableCollection<Player> Players { get; set; }
public void StartGame()
{
// This is as far as I've got...
base.NavigationService.NavigateToViewModel<GameViewModel>();
// How can I pass the Players collection from here to the GameViewModel?
}
}
public class GameViewModel : NavigationViewModelBase
{
public GameViewModel(INavigationService ns) : base(ns) { }
public ScoreBoardViewModel ScoreBoard { get; private set; }
public void InitializeScoreBoard(IEnumerable<Player> players)
{
ScoreBoard = new ScoreBoardViewModel(players);
}
}
Ideally, I would like to call InitializeScoreBoard
from within the GameViewModel
constructor, but as far as I have been able to tell it is not possible to pass the SetupGameViewModel.Players
collection to the GameViewModel
constructor.
The INavigationService.NavigateToViewModel<T>
(extension) method optionally takes an [object] parameter
argument, but this parameter does not seem to reach the view model constructor navigated to. And I cannot figure out how to explicitly call the GameViewModel.InitializeScoreBoard
method from the SetupGameViewModel.StartGame
method either, since the GameViewModel
has not been initialized at this stage.