/// <summary> /// Raised when the user loads the page. /// Register to the MVVM Light Messenger. /// Load the menu items. /// Register the background task to the system. /// </summary> /// <param name="e">Navigation event arguments</param> protected override async void OnNavigatedTo(NavigationEventArgs e) { base.OnNavigatedTo(e); // Register to the MVVM Light Messenger Messenger.Default.Register<VisualGenericGroup>(this, GoToMasterPage); Messenger.Default.Register<VisualGenericItem>(this, GoToDetailsPage); Messenger.Default.Register<PinnableObject>(this, Pin); Messenger.Default.Register<Uri>(this, GoToWebPage); Messenger.Default.Register<object>(this, GoToAboutPage); // Load items if (e.NavigationMode == NavigationMode.New) { IMainViewModel viewModel = (IMainViewModel)DataContext; if (App.IsInternetAvailable && viewModel.LoadMenuCommand.CanExecute(this)) { viewModel.LoadMenuCommand.Execute(this); } // Register the background tast to the system RegisterBackgroundTasksHelper helper = new RegisterBackgroundTasksHelper(); await helper.RegisterAsync(); // Update the application tile ApplicationTileManager manager = new ApplicationTileManager(); await manager.CreateAsync(); } }
/// <summary> /// Run the background task /// </summary> /// <param name="taskInstance">Returns task informations</param> public async void Run(IBackgroundTaskInstance taskInstance) { BackgroundTaskDeferral deferral = taskInstance.GetDeferral(); try { ApplicationTileManager manager = new ApplicationTileManager(); await manager.CreateAsync(); } finally { // Informs the system task is finished deferral.Complete(); } }