简体   繁体   English

导航和查询参数到另一个页面Windows Phone 8.1

[英]Navigation and Query parameter to another page Windows Phone 8.1

I have Windows Phone 8.1 app and I need to navigate from a main page to page "pizdec" with parameteres. 我有Windows Phone 8.1应用程序,我需要从主页导航到带有参数的页面“ pizdec”。

I have a cod which can do it in WP8.0, but how car rewrite it in code WP8.1, I don't know. 我有一个鳕鱼可以在WP8.0中完成,但是我不知道如何用WP8.1代码重写它。

Example: 例:

private void listbox1_SelectionChanged(object sender, SelectionChangedEventArgs e)
   {
     if (listbox1.SelectedItem != null)
     {
        var file = listbox1.SelectedItem as StorageFile;
        NavigationService.Navigate(new Uri("/pizdec.xaml?filename=" + file.Name, UriKind.Relative));
        listbox1.SelectedItem = null;
     }

I know that I need use this.Frame.Navigate() , but I do not understand how to rewrite it to 8.1 我知道我需要使用this.Frame.Navigate() ,但是我不知道如何将其重写为8.1

Code from pizdec.xaml : 来自pizdec.xaml代码:

protected override void OnNavigatedTo(NavigationEventArgs e)
   {
      base.OnNavigatedTo(e);
      string filename;

    if(NavigationContext.QueryString.TryGetValue("filename",out filename))
    {
        DisplayFile(filename);
    }

And NavigationContext , which no in 8.1 NavigationContext ,在8.1中没有

Please help 请帮忙

You use following, 您使用以下内容,

Frame.Navigate(typeof(pizdec), param); //a Windows app syntax. param is parameters you want to pass to pizdec.xaml

You can access the paramaters in next page as follows, 您可以按以下方式访问下一页中的参数,

string filename = e.NavigationParameter as string;

Microsoft is trying to make syntax of Windows & windows phone app similar, hence the change. 微软正试图使Windows和Windows Phone应用程序的语法相似,因此有所改变。 More info here 更多信息在这里

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM