コード例 #1
0
        /// <summary>
        /// Creates secondary tile if it is not yet created or removes the tile if it already exists.
        /// </summary>
        /// <param name="sender">Sender object</param>
        /// <param name="e">Event arguments</param>
        private async void ApplicationBar_PinTile(object sender, RoutedEventArgs e)
        {
            bool removeTile = SecondaryTile.Exists(TILE_ID);

            if (removeTile)
            {
                await RemoveBackgroundTaskAsync("StepTriggered");
            }
            else
            {
                ApiSupportedCapabilities caps = await SenseHelper.GetSupportedCapabilitiesAsync();

                // Use StepCounterUpdate to trigger live tile update if it is supported. Otherwise we use time trigger
                if (caps.StepCounterTrigger)
                {
                    var myTrigger = new DeviceManufacturerNotificationTrigger(SenseTrigger.StepCounterUpdate, false);
                    await RegisterBackgroundTaskAsync(myTrigger, "StepTriggered", "BackgroundTasks.StepTriggerTask");
                }
                else
                {
                    BackgroundAccessStatus status = await BackgroundExecutionManager.RequestAccessAsync();

                    IBackgroundTrigger trigger = new TimeTrigger(15, false);
                    await RegisterBackgroundTaskAsync(trigger, "StepTriggered", "BackgroundTasks.StepTriggerTask");
                }
            }
            await CreateOrRemoveTileAsync(removeTile);
        }