In Stack Careers Browser when a career is selected from the main page view, I have the following in the OnNavigatedTo event on the DetailsPage.xaml.cs.
if (DataContext == null)
{
string selectedIndex = "";
if (NavigationContext.QueryString.TryGetValue("selectedItem", out selectedIndex))
{
**int index = int.Parse(selectedIndex);**
**DataContext = _vm = new JobPostingViewModel(App.ViewModel.JobPostings[index]);**
Indicators.SetIndicators(this, DataContext);
await _vm.ScrapeThatScreenAsync(_vm.JobPosting.Id);
}
}
The corresponding viewmodel has a constructor that looks like this:
public JobPostingViewModel(JobPosting jobPosting)
{
if (jobPosting == null)
throw new ArgumentNullException("jobPosting");
JoelTestResults = new ObservableCollection<JoelTestResult>();
// JoelTestResults = new ObservableCollection<string>(){"a","b","c"};
_jobPosting = jobPosting;
if (jobPosting.Categories != null && jobPosting.Categories.Any())
ProcessCategories(jobPosting.Categories);
}
Where I require some basic object in order to process more information and display it in the windows phone 8 manner.