我正在尝试从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.
答案 0 :(得分:0)
嗯,看起来你的调试器变得古怪。
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