Navigating from App.xaml.cs

前端 未结 3 1241
执笔经年
执笔经年 2021-02-20 12:46

I want to add an application bar to multiple pages of my app. So, I\'m defining the application bar as an application resource so that it can be used by multiple pages. Now, the

3条回答
  •  一个人的身影
    2021-02-20 13:12

    an other way to navigate to an other page from App.xaml.cs (using the app bar) is using the rootFrame var (at the end line):

    private Frame rootFrame = null;
    protected override async void OnLaunched(LaunchActivatedEventArgs args)
    {
        ...
        SettingsPane.GetForCurrentView().CommandsRequested += App_CommandRequested;
    }
    
    private void App_CommandRequested(SettingsPane sender, SettingsPaneCommandsRequestedEventArgs args)
    {
    SettingsCommand cmdSnir = new SettingsCommand("cmd_snir", "Snir's Page", 
                  new Windows.UI.Popups.UICommandInvokedHandler(onSettingsCommand_Clicked));
    args.Request.ApplicationCommands.Add(cmdSnir);
    }
    
    void onSettingsCommand_Clicked(Windows.UI.Popups.IUICommand command)
    {
    if (command.Id.ToString() == "cmd_snir")
          rootFrame.Navigate(typeof(MainPage)); //, UriKind.RelativeOrAbsolute);
    
    }
    

提交回复
热议问题