C# 从NavigationContext获取数据时出错

C# 从NavigationContext获取数据时出错,c#,windows-phone-8.1,windows-phone-sl-8.1,C#,Windows Phone 8.1,Windows Phone Sl 8.1,我正在Visual Studio 2013中使用C#创建一个提醒应用程序。其中一个页面用于启动通知 我的代码是: protected override void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); string Combobox = ""; string Content = ""; NavigationContext.QueryString.T

我正在Visual Studio 2013中使用C#创建一个提醒应用程序。其中一个页面用于启动通知

我的代码是:

protected override void OnNavigatedTo(NavigationEventArgs e)
    {

       base.OnNavigatedTo(e);

       string Combobox = "";
       string Content = "";

     NavigationContext.QueryString.TryGetValue("param1", out Combobox);

     NavigationContext.QueryString.TryGetValue("param2", out Content);

     param1TextBlock.Text = Combobox;
     param2TextBlock.Text = Content;     

    }
但错误发生在这一部分:

     NavigationContext.QueryString.TryGetValue("param1", out Combobox);

     NavigationContext.QueryString.TryGetValue("param2", out Content);
错误是:

错误1非静态字段需要对象引用, 方法或属性 'System.Windows.Navigation.NavigationContext.QueryString.get'

有什么想法吗?

List MyStringsList=new List();
List<string> MyStringsList = new List<string>();

this.Frame.Navigate(typeof(PageName),MyStringsList);
this.Frame.Navigate(typeof(PageName),MyStringsList);
此代码用于带参数的导航,您可以在OnNavigatedTo事件中的“导航到”页面获取这些参数:

protected override void OnNavigatedTo(NavigationEventArgs e)
{

   List<string> MyRecievedParameters = e.Parameter as List<string>;
}
受保护的覆盖无效OnNavigatedTo(NavigationEventArgs e)
{
将MyReceivedParameters=e.参数列为列表;
}

您很可能创建了“Windows Phone”应用程序项目,而您需要创建“Windows Phone Silverlight”才能访问NavigationContext类。

只是猜测,但变量名“Content”和“Combobox”可能会干扰内置类型。尝试重命名这两个变量。它是通用应用程序还是Silverlight应用程序?编译器似乎试图访问类型
NavigationContext
,而不是页面中定义的属性(通过继承
PhoneApplicationPage
),但我无法理解原因。您应该尝试使用
this
关键字,看看是否会得到更明确的错误消息:
this.NavigationContext.QueryString.TryGetValue(“param1”,out组合框)我尝试了这种方法,但出现以下错误:错误1“FastHealing.ShowParams”不包含“NavigationContext”的定义,并且找不到接受“FastHealing.ShowParams”类型的第一个参数的扩展方法“NavigationContext”(是否缺少using指令或程序集引用?)不要将字符串初始化为
。当您将字符串作为
输出
参数传递时,只声明它们。此解决方案在silverlight wp8.1应用程序中不起作用