コード例 #1
0
 private void DetectActivationKind(NavigationEventArgs e)
 {
     // If the app was opened as a result of being activated by some action, the details of that
     // activation will be found in the NavigationEventArgs.Parameter property.
     if (e.Parameter != null && e.Parameter is WalletActionActivatedEventArgs)
     {
         // In this example, we'll just inform the user that the app was activated due to an action.
         // In a real-life scenario, the app would determine what to do with this type of activation.
         WalletActionActivatedEventArgs walletArgs = e.Parameter as WalletActionActivatedEventArgs;
         string message = String.Format("Launched through a wallet action.\nAction Kind: {0}\nAction Id: {1}\nItem Id: {2}", walletArgs.ActionKind.ToString(), walletArgs.ActionId, walletArgs.ItemId);
         NotifyUser(message, NotifyType.StatusMessage);
     }
 }
コード例 #2
0
        /// <summary>
        /// The OnActivated event occurs when the app has been activated through an action other than the normal opening of the app
        /// by the user from the start page. In this Wallet sample, activation occurs when the user taps on
        /// an action on a card associated with this app in Wallet.
        /// In this event handler, the activation arguments are then passed to the MainPage.
        /// To see how this activation is handled in this sample, see DetectActivationKind in MainPage.xaml.cs
        /// </summary>
        /// <param name="e"></param>
        protected async override void OnActivated(IActivatedEventArgs e)
        {
            // Check whether app was activated due to a Wallet action
            if (e.Kind == ActivationKind.WalletAction)
            {
                Debug.WriteLine("Activated by a Wallet action");

                // Cast the incoming arguments to a WalletActionActivatedEventArgs object
                WalletActionActivatedEventArgs walletActivationArgs = e as WalletActionActivatedEventArgs;

                // Check the properties of the WalletActionActivatedEventArgs to determine what
                // action and item caused the app to be activated.
                Debug.WriteLine("ActionId = {0}", walletActivationArgs.ActionId);
                Debug.WriteLine("ActionKind = {0}", walletActivationArgs.ActionKind);
                Debug.WriteLine("ItemId = {0}", walletActivationArgs.ItemId);
            }

            CreateRootFrame();

            // Restore the saved session state only when appropriate
            if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
            {
                try
                {
                    await SuspensionManager.RestoreAsync();
                }
                catch (SuspensionManagerException)
                {
                    //Something went wrong restoring state.
                    //Assume there is no state and continue
                }
            }

            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);
            }

            Window.Current.Activate();
        }