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 ?
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
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With