Does not contain a definition for NavigationContex

2019-08-02 19:14发布

When I work this code in NavigationContext I am getting an error.

protected void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e) {
  base.OnNavigatedTo(e);   
  string parameterValue = NavigationContext.QueryString["parameter"];
}

1条回答
▲ chillily
2楼-- · 2019-08-02 19:33

In Windows Phone 8.1 RT model app there is no need to pass parameters in URI format. Now you can send them as an object. You can create your own class for this, for example:

public class MyParametersClass
{
    public string Parameter1 { get; set; }
    public int Parameter2 { get; set; }
    public double Parameter3 { get; set; }
}

When you want to navigate from one page to another you use Frame.Navigate() method:

MyParametersClass myParameters = new MyParametersClass(); // Initialize parameters    
myParameters.Parameters1 = "Trololo"; // Let set some values

Frame.Navigate(typeof(SomePage), myParameters); // Navigate to some page with parameters

When navigation is completed, you can just get object with your parameters from property named Parameter. You do this in a page you wanted to navigate.

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    MyParametersClass myParameters = e.Parameter as MyParametersClass;
}
查看更多
登录 后发表回答