我正在開發使用的WinRT Caliburn.Micro一個Windows應用商店的應用程序的遊戲,我依靠導航框架。如何使用WinRT Caliburn.Micro將參數傳遞給導航視圖模型?
我對遊戲的設置(定義播放器)和實際遊戲視圖模型。從設置導航到遊戲時,我想將玩家集合傳遞給遊戲視圖模型。我怎樣才能做到這一點?
示意,我的視圖模型目前是這樣的:
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);
}
}
理想情況下,我想打電話給InitializeScoreBoard
從構造函數中,但據我已經能夠告訴它是不可能的將SetupGameViewModel.Players
集合傳遞給構造函數。
INavigationService.NavigateToViewModel<T>
(擴展)方法可選地採用[object] parameter
參數,但此參數似乎未達到導航到的視圖模型構造函數。而且我也不知道如何明確地調用SetupGameViewModel.StartGame
方法中的GameViewModel.InitializeScoreBoard
方法,因爲尚未在此階段初始化。
謝謝你,它節省了我很多的時間。 – jimpanzer 2013-05-24 07:27:55
在Rob自己的這篇文章中,他解釋說,這是因爲Windows Phone中基於導航的系統是基於Uri的,它不支持複雜的反序列化。 http://caliburnmicro.codeplex.com/discussions/267562 – 2013-09-04 14:58:34