/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { // How did the app exit the last time it was run (if at all) ApplicationExecutionState previousState = e.PreviousExecutionState; // What kind of launch is this? ActivationKind activationKind = e.Kind; //.. Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { // Set the frame navigation state that was serialized as a string when we suspended if (ApplicationData.Current.LocalSettings.Values.ContainsKey("NavigationState")) { rootFrame.SetNavigationState((string)ApplicationData.Current.LocalSettings.Values["NavigationState"]); } } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter rootFrame.Navigate(typeof(MainPage), e.Arguments); } // Ensure the current window is active Window.Current.Activate(); Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested; // Every time the Frame navigates, set the visibility of the Shell-drawn back button // appropriate to whether there is anywhere to go back to rootFrame.Navigated += (s, a) => { if (rootFrame.CanGoBack) { // Setting this visible is ignored on Mobile and when in tablet mode! SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible; } else { SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed; } }; }
/// <summary> /// 在应用程序由最终用户正常启动时进行调用。 /// 将在启动应用程序以打开特定文件等情况下使用。 /// </summary> /// <param name="e">有关启动请求和过程的详细信息。</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { ApplicationExecutionState previousState = e.PreviousExecutionState; // What kind of launch is this? ActivationKind activationKind = e.Kind; Frame rootFrame = Window.Current.Content as Frame; // 不要在窗口已包含内容时重复应用程序初始化, // 只需确保窗口处于活动状态 if (rootFrame == null) { // 创建要充当导航上下文的框架,并导航到第一页 rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: 从之前挂起的应用程序加载状态 if (ApplicationData.Current.LocalSettings.Values.ContainsKey("NavigationState")) { rootFrame.SetNavigationState((string)ApplicationData.Current.LocalSettings.Values["NavigationState"]); } } // 将框架放在当前窗口中 Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { // 当导航堆栈尚未还原时,导航到第一页, // 并通过将所需信息作为导航参数传入来配置 // 参数 rootFrame.Navigate(typeof(MainPage), e.Arguments); } // 确保当前窗口处于活动状态 Window.Current.Activate(); Windows.UI.Core.SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested; // Every time the Frame navigates, set the visibility of the Shell-drawn back button // appropriate to whether there is anywhere to go back to rootFrame.Navigated += (s, a) => { if (rootFrame.CanGoBack) { // Setting this visible is ignored on Mobile and when in tablet mode! SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible; } else { SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed; } }; }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { ActivationKind activationKind = e.Kind; //#if DEBUG // if (System.Diagnostics.Debugger.IsAttached) // { // this.DebugSettings.EnableFrameRateCounter = true; // } //#endif Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter rootFrame.Navigate(typeof(MainPage), e.Arguments); } // Ensure the current window is active Window.Current.Activate(); SystemNavigationManager.GetForCurrentView().BackRequested += App_BackRequested; rootFrame.Navigated += (s, a) => { if (rootFrame.CanGoBack) { SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Visible; } else { SystemNavigationManager.GetForCurrentView().AppViewBackButtonVisibility = AppViewBackButtonVisibility.Collapsed; } }; }
// Use the UWP version of AppInstance::GetActivatedEventArgs. private void GetActivationInfoUwp() { // The UWP GetActivatedEventArgs returns an IActivatedEventArgs, // which can be directly cast to the specific activation type it represents. IActivatedEventArgs args = Windows.ApplicationModel.AppInstance.GetActivatedEventArgs(); ActivationKind kind = args.Kind; OutputMessage($"ActivationKind: {kind}"); if (kind == ActivationKind.Launch) { if (args is ILaunchActivatedEventArgs launchArgs) { string argString = launchArgs.Arguments; string[] argStrings = argString.Split(); foreach (string arg in argStrings) { if (!string.IsNullOrWhiteSpace(arg)) { OutputMessage(arg); } } } } else if (kind == ActivationKind.File) { if (args is IFileActivatedEventArgs fileArgs) { IStorageItem file = fileArgs.Files.FirstOrDefault(); OutputMessage(file.Name); } } else if (kind == ActivationKind.Protocol) { if (args is IProtocolActivatedEventArgs protocolArgs) { Uri uri = protocolArgs.Uri; OutputMessage(uri.AbsoluteUri); } } else if (kind == ActivationKind.StartupTask) { if (args is IStartupTaskActivatedEventArgs startupArgs) { OutputMessage(startupArgs.TaskId); } } }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used such as when the application is launched to open a specific file. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { Frame rootFrame = Window.Current.Content as Frame; // Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { ApplicationExecutionState previousStae = e.PreviousExecutionState; ActivationKind activationKind = e.Kind; // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: Load state from previously suspended application } // Place the frame in the current Window Window.Current.Content = rootFrame; } if (e.PrelaunchActivated == false) { if (rootFrame.Content == null) { // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter var str = Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily; if (str == "Windows.Desktop") { rootFrame.Navigate(typeof(OndernemingenPage), e.Arguments); } else { rootFrame.Navigate(typeof(OndernemingenPage_Mobile), e.Arguments); } } // Ensure the current window is active Window.Current.Activate(); } }
protected async override void OnActivated(IActivatedEventArgs e) { IAppPage page = GetCurrentPage() as IAppPage; ActivationKind kind = e.Kind; switch (kind) { case Windows.ApplicationModel.Activation.ActivationKind.VoiceCommand: //await Cortana.InstallFilenamePhrase(); RespondToForegroundVoiceCommand(e as VoiceCommandActivatedEventArgs, page); break; //case ActivationKind.Protocol: // RespondToBackgroundVoiceCommand(e as ProtocolActivatedEventArgs, page); // break; } }
/// <summary> /// 在应用程序由最终用户正常启动时进行调用。 /// 将在启动应用程序以打开特定文件等情况下使用。 /// </summary> /// <param name="e">有关启动请求和过程的详细信息。</param> protected override void OnLaunched(LaunchActivatedEventArgs e) { ApplicationExecutionState previousState = e.PreviousExecutionState; ActivationKind activationKind = e.Kind; Frame rootFrame = Window.Current.Content as Frame; // 不要在窗口已包含内容时重复应用程序初始化, // 只需确保窗口处于活动状态 if (rootFrame == null) { // 创建要充当导航上下文的框架,并导航到第一页 rootFrame = new Frame(); rootFrame.NavigationFailed += OnNavigationFailed; rootFrame.Navigated += OnNavigated; SystemNavigationManager.GetForCurrentView().BackRequested += OnBackRequested; if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) { //TODO: 从之前挂起的应用程序加载状态 if (ApplicationData.Current.LocalSettings.Values.ContainsKey("NavigationState")) { rootFrame.SetNavigationState((string)ApplicationData.Current.LocalSettings.Values["NavigationState"]); } } // 将框架放在当前窗口中 Window.Current.Content = rootFrame; } if (e.PrelaunchActivated == false) { if (rootFrame.Content == null) { // 当导航堆栈尚未还原时,导航到第一页, // 并通过将所需信息作为导航参数传入来配置 // 参数 rootFrame.Navigate(typeof(MainPage), e.Arguments); } // 确保当前窗口处于活动状态 Window.Current.Activate(); } }
internal LaunchActivatedEventArgs(ActivationKind kind, string arguments) { Arguments = arguments; Kind = kind; }
protected override Task StartAsync(Frame frame, ActivationKind activationKind, ApplicationExecutionState previousExecutionState) { SetupTelemetry(); return(Task.CompletedTask); }
private void CheckActivationKind(ActivationKind kind) { AppLog.Write(kind.ToString()); switch (kind) { case ActivationKind.Launch: break; case ActivationKind.Search: break; case ActivationKind.ShareTarget: break; case ActivationKind.File: break; case ActivationKind.Protocol: break; case ActivationKind.FileOpenPicker: break; case ActivationKind.FileSavePicker: break; case ActivationKind.CachedFileUpdater: break; case ActivationKind.ContactPicker: break; case ActivationKind.Device: break; case ActivationKind.PrintTaskSettings: break; case ActivationKind.CameraSettings: break; case ActivationKind.RestrictedLaunch: break; case ActivationKind.AppointmentsProvider: break; case ActivationKind.Contact: break; case ActivationKind.LockScreenCall: break; case ActivationKind.VoiceCommand: break; case ActivationKind.LockScreen: break; case ActivationKind.PickerReturned: break; case ActivationKind.WalletAction: break; case ActivationKind.PickFileContinuation: break; case ActivationKind.PickSaveFileContinuation: break; case ActivationKind.PickFolderContinuation: break; case ActivationKind.WebAuthenticationBrokerContinuation: break; case ActivationKind.WebAccountProvider: break; case ActivationKind.ComponentUI: break; case ActivationKind.ProtocolForResults: break; case ActivationKind.ToastNotification: break; case ActivationKind.DialReceiver: break; default: throw new ArgumentOutOfRangeException(nameof(kind), kind, null); } }
protected virtual bool ShouldAppRestoreAfterTermination(ActivationKind kind) { // Only restore state if the app is launched normally return kind == ActivationKind.Launch; }
// *** Constructors *** public MockActivatedEventArgs(ActivationKind kind) { this.Kind = kind; }
internal LaunchActivatedEventArgs(ActivationKind kind, string?arguments) { Arguments = arguments; UWPLaunchActivatedEventArgs = new Windows.ApplicationModel.Activation.LaunchActivatedEventArgs(kind, arguments); }
/// <summary> /// Invoked when the application is launched normally by the end user. Other entry points /// will be used when the application is launched to open a specific file, to display /// search results, and so forth. /// </summary> /// <param name="e">Details about the launch request and process.</param> protected override async void OnLaunched(LaunchActivatedEventArgs e) { #if DEBUG if (System.Diagnostics.Debugger.IsAttached) { this.DebugSettings.EnableFrameRateCounter = true; } #endif ApplicationExecutionState previousState = e.PreviousExecutionState; ActivationKind activationKind = e.Kind; Frame rootFrame = Window.Current.Content as Frame; if (rootFrame == null) { rootFrame = new Frame(); //SuspensionManager.RegisterFrame(rootFrame, "AppFrame"); rootFrame.CacheSize = 2; // Set the default language rootFrame.Language = Windows.Globalization.ApplicationLanguages.Languages[0]; //if (e.PreviousExecutionState == ApplicationExecutionState.Terminated) //{ // try // { // await SuspensionManager.RestoreAsync(); // } // catch (SuspensionManagerException) // { // // Something went wrong restoring state. // // Assume there is no state and continue. // } //} Window.Current.Content = rootFrame; } if (rootFrame.Content == null) { if (rootFrame.ContentTransitions != null) { this.transitions = new TransitionCollection(); foreach (var c in rootFrame.ContentTransitions) { this.transitions.Add(c); } } rootFrame.ContentTransitions = null; rootFrame.Navigated += this.RootFrame_FirstNavigated; // When the navigation stack isn't restored navigate to the first page, // configuring the new page by passing required information as a navigation // parameter. if (!rootFrame.Navigate(typeof(View.HubPage), e.Arguments)) { throw new Exception("Failed to create initial page"); } } // Ensure the current window is active. Window.Current.Activate(); }
public ActivationEventArgs(ActivationKind kind) { ActivationKind = kind; }
private static void CheckKind(ActivationKind kind) { switch (kind) { case ActivationKind.Launch: break; case ActivationKind.Search: break; case ActivationKind.ShareTarget: break; case ActivationKind.File: break; case ActivationKind.Protocol: break; case ActivationKind.FileOpenPicker: break; case ActivationKind.FileSavePicker: break; case ActivationKind.CachedFileUpdater: break; case ActivationKind.ContactPicker: break; case ActivationKind.Device: break; case ActivationKind.PrintTaskSettings: break; case ActivationKind.CameraSettings: break; case ActivationKind.RestrictedLaunch: break; case ActivationKind.AppointmentsProvider: break; case ActivationKind.Contact: break; case ActivationKind.LockScreenCall: break; case ActivationKind.VoiceCommand: break; case ActivationKind.LockScreen: break; case ActivationKind.PickerReturned: break; case ActivationKind.WalletAction: break; case ActivationKind.PickFileContinuation: break; case ActivationKind.PickSaveFileContinuation: break; case ActivationKind.PickFolderContinuation: break; case ActivationKind.WebAuthenticationBrokerContinuation: break; case ActivationKind.WebAccountProvider: break; case ActivationKind.ComponentUI: break; case ActivationKind.ProtocolForResults: break; case ActivationKind.ToastNotification: break; case ActivationKind.DialReceiver: break; default: throw new ArgumentOutOfRangeException(); } }
protected override Task StartAsync(Frame frame, ActivationKind activationKind, ApplicationExecutionState previousExecutionState, PrelaunchStage prelaunchStage) { frame.Navigation.Navigate(typeof(MessengerPage)); return(Task.CompletedTask); }
protected virtual Task StartAsync(Frame frame, ActivationKind activationKind, ApplicationExecutionState previousExecutionState, PrelaunchStage prelaunchStage) => Task.FromResult <Object>(null);