// Performs one of the following tasks when a LOB app is tapped: installs the app, starts the app, or stops // the installation of the app. private void CompanyAppList_SelectionChanged(object sender, SelectionChangedEventArgs e) { LongListSelector companyAppList = (LongListSelector)sender; try { // If selected item is null (no selection) do nothing. if (companyAppList.SelectedItem == null) { return; } CompanyAppViewModel selectedApp = companyAppList.SelectedItem as CompanyAppViewModel; // Clear the selection in the list. companyAppList.SelectedItem = null; // App is not installed yet, so start installing it. if (selectedApp.Status == Status.NotInstalled || selectedApp.Status == Status.Canceled) { Windows.Foundation.IAsyncOperationWithProgress <PackageInstallResult, uint> result; selectedApp.Status = Status.Installing; selectedApp.ProgressValue = 0; result = InstallationManager.AddPackageAsync(selectedApp.Title, selectedApp.XapPath); result.Completed = InstallCompleted; result.Progress = InstallProgress; selectedApp.Result = result; } // App is already installed, so start it. else if (selectedApp.Status == Status.Installed) { this.LaunchApp(selectedApp.ProductId); } // App is in the process of installing; determine if the user is trying to stop the installation. else if (selectedApp.Status == Status.Installing || selectedApp.Status == Status.InstallFailed) { if (selectedApp.Result != null) { MessageBoxResult result = MessageBox.Show("Are you sure you want to stop the company app installation?", "Stop installation?", MessageBoxButton.OKCancel); if (result == MessageBoxResult.OK) { selectedApp.Result.Cancel(); selectedApp.Status = Status.Canceled; } } else { foreach (var installingPackage in InstallationManager.GetPendingPackageInstalls()) { installingPackage.Cancel(); } selectedApp.Status = Status.Canceled; } } } catch (System.Exception ex) { MessageBox.Show(ex.ToString()); companyAppList.SelectedItem = null; } }