NavigationContext.QueryString.TryGetValue NullReferenceException in WP7.5
c#, windows-phone-7, windows-phone-7.1, wpf, xaml
Solution
You shouldn't call this code from the constructor, as the `NavigationContext` isn't initialized yet. Use the `OnNavigatedTo` event instead:
protected override void OnNavigatedTo(NavigationEventArgs e)
{
string strCodeTiers = string.Empty;
if (NavigationContext.QueryString.TryGetValue("selectedItem",out strCodeTiers))
{
// Whatever
}
}
Problem
I would like to pass a string between to pages in 7.5 I have read some guides, but, I have a `NullReferenceException` . Page.xml.cs : ``` var item = ListBoxTiers.SelectedItem as CTiers; NavigationService.Navigate(new Uri("/DetailTiers.xaml?selectedItem=" + item.m_strCode, UriKind.Relative)); ``` If i look at the debugger, i can see : `"DetailTiers.xaml?selectedItem=C0000015"` In my page , Page2.xms.cs: ``` public Page2() { InitializeComponent(); string strCodeTiers = string.Empty; if (NavigationContext.QueryString.TryGetValue("selectedItem",out strCodeTiers)) // Exception here { } ``` Anyone know where is my error ?