【问题标题】:C# WP8 Getting page URL adress with parameterC# WP8 获取带参数的页面 URL 地址
【发布时间】:2014-11-29 16:48:52
【问题描述】:

我正在尝试从 URL 中获取参数,但出现错误。 这是我的代码:

protected override void OnNavigatedTo(System.Windows.Navigation.NavigationEventArgs e)
    {
        base.OnNavigatedTo(e);
        string str = "";
        if (NavigationContext.QueryString.TryGetValue("data", out str))
        {
            MessageBox.Show("k");
        }
    }


private void aktualizuj(object sender, DateTimeValueChangedEventArgs e)
{
        var btndate = sender as DatePicker;
        NavigationService.Navigate(new Uri("dieta.xaml?data=" + btndate.Value.Value.Date.ToString(),UriKind.Relative));
}

我收到的错误如下:

    A first chance exception of type 'System.MissingMethodException' occurred in mscorlib.ni.dll
If there is a handler for this exception, the program may be safely continued.

【问题讨论】:

    标签: c# windows-phone-8 navigation


    【解决方案1】:

    嗯,看起来你的调试器有点古怪。

    NavigationService.Navigate(new Uri("dieta.xaml?data=" +
        btndate.Value.Value.Date.ToString(),UriKind.Relative));
    

    应该抛出异常:

    Navigation is only supported to relative URIs that are fragments, or begin with '/', or which contain ';component/'. Parameter name: uri

    所以你应该把它改成

    NavigationService.Navigate(new Uri("/dieta.xaml?data=" +
        btndate.Value.Value.Date.ToString(),UriKind.Relative));
    

    如果你要使用UriKind.Relative

    【讨论】:

      猜你喜欢
      • 2012-05-28
      • 2012-06-23
      • 1970-01-01
      • 1970-01-01
      • 2011-07-20
      • 2018-03-29
      • 1970-01-01
      • 2017-10-16
      • 1970-01-01
      相关资源
      最近更新 更多