protected async override void OnFileActivated(FileActivatedEventArgs e) { var args = e as FileActivatedEventArgs; if (args.Files.Count > 0) { string json = await FileIO.ReadTextAsync((IStorageFile)args.Files[0]); Setting.FileStart = true; Setting.FileData = json; ApplyColorToTitleBar(); var rootFrame = new Frame(); Window.Current.Content = rootFrame; if (RouterAPI.HasLogin()) { var loginRes = await RouterAPI.Login(); if (loginRes) { rootFrame.Navigate(typeof(MainPage), e); } else { rootFrame.Navigate(typeof(LoginPage), e); } } else { rootFrame.Navigate(typeof(LoginPage), e); } Window.Current.Activate(); } }
/// <summary> /// 在应用程序由最终用户正常启动时进行调用。 /// 将在启动应用程序以打开特定文件等情况下使用。 /// </summary> /// <param name="e">有关启动请求和过程的详细信息。</param> protected override async void OnLaunched(LaunchActivatedEventArgs e) { #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { /* * this.DebugSettings.EnableFrameRateCounter = false; * debugView = CoreApplication.CreateNewView(); * int id = 0; * await debugView.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, () => * { * debugFrame = new Frame(); * debugFrame.Navigate(typeof(DebugPage), null); * Window.Current.Content = debugFrame; * Window.Current.Activate(); * id = ApplicationView.GetForCurrentView().Id; * }); * bool viewShown = await ApplicationViewSwitcher.TryShowAsStandaloneAsync(id); */ } #endif Frame rootFrame = Window.Current.Content as Frame; // 不要在窗口已包含内容时重复应用程序初始化, // 只需确保窗口处于活动状态 if (rootFrame == null) { // 创建要充当导航上下文的框架,并导航到第一页 rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: 从之前挂起的应用程序加载状态 } // 将框架放在当前窗口中 Window.Current.Content = rootFrame; } if (e.PrelaunchActivated == false) { if (rootFrame.Content == null) { // 当导航堆栈尚未还原时,导航到第一页, // 并通过将所需信息作为导航参数传入来配置 // 参数 ApplyColorToTitleBar(); if (RouterAPI.HasLogin()) { var loginRes = await RouterAPI.Login(); if (loginRes) { rootFrame.Navigate(typeof(MainPage), e); } else { rootFrame.Navigate(typeof(LoginPage), e); } } else { rootFrame.Navigate(typeof(LoginPage), e); } } // 确保当前窗口处于活动状态 Window.Current.Activate(); } }
override protected async void OnActivated(IActivatedEventArgs e) { if (e.Kind == ActivationKind.ContactPanel) { Setting.ContactStart = true; ApplyColorToTitleBar(); // Create a Frame to act as the navigation context and navigate to the first page var rootFrame = new Frame(); // Place the frame in the current Window Window.Current.Content = rootFrame; if (RouterAPI.HasLogin()) { var loginRes = await RouterAPI.Login(); if (loginRes) { rootFrame.Navigate(typeof(PeopleViewPage), e); } else { rootFrame.Navigate(typeof(LoginPage), e); } } else { rootFrame.Navigate(typeof(LoginPage), e); } // Navigate to the page that shows the Contact UI. // Ensure the current window is active Window.Current.Activate(); } else if (e.Kind == ActivationKind.ToastNotification) { var args = e as ToastNotificationActivatedEventArgs; if (args.Argument == "Select") { Setting.ToastStart = true; ApplyColorToTitleBar(); // Create a Frame to act as the navigation context and navigate to the first page var rootFrame = new Frame(); // Place the frame in the current Window Window.Current.Content = rootFrame; if (Class.RouterAPI.HasLogin()) { var loginRes = await RouterAPI.Login(); if (loginRes) { rootFrame.Navigate(typeof(MainPage), e); } else { rootFrame.Navigate(typeof(LoginPage), e); } } else { rootFrame.Navigate(typeof(LoginPage), e); } Window.Current.Activate(); } } }