OK, just putting it out there, Caliburn.Micro
has unified navigation for WP8 and WinRT:
NavigationService.UriFor<TargetViewModel>().WithParam(x => x.TargetProperty, ValueToPass).Navigate();
And you can chain WithParam
for multiple parameters. Now there are some constraints, not all types go through, I'm not quite sure what the exact reason for that is, but it has something to do how the navigation works in WinRT. There was a mention of it somewhere in Caliburn.Micro
discussion section.
Anyway, you can navigate this way. Don't rely on constructor though, It will call OnInitialize
and OnActivate
. So, just to cut it into the example:
NavigationService.UriFor<DetailsViewModel>().WithParam(x => x.Id, SelectedDetailsId).Navigate();
then in the DetailsViewModel
:
protected override void OnInitialize()
{
//Here you'll have Id property initialized to 'SelectedDetailsId' from the previous screen.
}
So, in pure theory, you could do:
NavigationService.UriFor<GameViewModel>().WithParam(x => x.Players, Players).Navigate();
in the setup and then:
public class GameViewModel
{
public GameViewModel(INavigationService ns) : base(ns)
{
//It would probably be good to initialize Players here to avoid null
}
public ScoreBoardViewModel ScoreBoard { get; private set; }
public IObservableCollection<Player> Players {get;set;}
protected void OnInitialize()
{
//If everything goes as expected, Players should be populated now.
ScoreBoard = new ScoreBoard(Players);
}
}
In practice though, I don't think that passing a complex construct like that (collection of classes etc) is going to work.
More primitive types work just fine (int
, string
, DateTime
etc., but e.g. URI
didn't work for me, was always null
), so worst-case scenario/workaround is, for example, to serialize the Players
list to a temp file before the navigation and pass the file path as string to deserialize in the GameViewModel
.
There are people more involved in the framework roaming the SO, they might give you more valuable insight.