简体   繁体   English

在应用程序启动时检查启动Uri

[英]Check Launch Uri when Application Starts

Is it possible to check whether an app was navigated to from a secondary tile in App.xaml.cs ? 是否可以检查是否从App.xaml.cs的辅助图块导航到应用程序? I need to somehow link a user to the WiFi launch uri from a secondary tile on the start screen without the user navigating to the MainPage first. 我需要以某种方式将用户从开始屏幕上的辅助磁贴链接到WiFi启动uri,而无需用户先导航到MainPage。 I'd like to check in either Application_Launching or Application_Activated . 我想签入Application_LaunchingApplication_Activated Currently I am doing this in the OnNavigatedTo event in MainPage which is displaying the MainPage before the built in WiFi app, and this is confusing as well as annoying for the user. 当前,我正在MainPage的OnNavigatedTo事件中执行此操作,该事件在内置WiFi应用程序之前显示MainPage,这OnNavigatedTo用户感到困惑又烦人。

MainPage.xaml.cs MainPage.xaml.cs

//From Pinned Tile
protected async override void OnNavigatedTo(NavigationEventArgs e)
    {
        if (NavigationContext.QueryString.ContainsKey(Constants.Key))
        {
            string _title = null;
            _title = NavigationContext.QueryString[Constants.Key];

            if (_title != null)
            {
                switch (_title)
                {
                    case "Tile_WiFi":
                        await Windows.System.Launcher.LaunchUriAsync(new Uri("ms-settings-wifi:"));
                        break;

                NavigationContext.QueryString.Remove(Constants.Key);
            }
        }
    }

I am not able to use NavigationService or NavigationContext within App.xaml.cs. 我无法在App.xaml.cs中使用NavigationServiceNavigationContext Is there an alternative? 还有其他选择吗? To note, I got this idea from other apps performing this function on the Store and they do not have the issue of navigating to the MainPage first before the built in app. 需要注意的是,我是从其他在商店上执行此功能的应用程序中得到这个想法的,他们在内置应用程序之前没有先导航到MainPage的问题。

private void Application_Launching(object sender, LaunchingEventArgs e)
    {
        //check if we are to navigate to WiFi here
    }

Secondary tiles can have a navigation URI that points directly to a page, and that page will be navigated to directly when the user taps the secondary tile. 辅助磁贴可以具有直接指向页面的导航URI,当用户点击辅助磁贴时,该页面将直接导航到该页面。

If you do not want to show any page, but launch another app you can try to handle the RootFrame.Navigating event, then check the uri and query of the NavigatingCancelEventArgs parameter and cancel the navigation. 如果您不想显示任何页面,而是启动另一个应用程序,则可以尝试处理RootFrame.Navigating事件,然后检查uri和NavigatingCancelEventArgs参数查询并取消导航。

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

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