/// <summary> /// Starts downloading the currently selected products and configures the UI elements. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void StartDownloads(object sender, RoutedEventArgs e) { var marginSetting = new Thickness(0, 0, 0, 10); IEnumerable <Licence> licencesForProductsToDownload = licenceManager .GetLicences() .Where(q => (selectedDownloads.SelectedItems) .Cast <ListBoxItem>() .Select(x => x.Name) .Contains(q.GetLicenceLocatorToken())) .ToList(); if (!licencesForProductsToDownload.Any()) { return; } startDownloadButton.IsEnabled = false; selectedDownloads.IsEnabled = false; foreach (Licence licence in licencesForProductsToDownload) { var grid = new Grid { Name = $"{licence.GetLicenceLocatorToken()}grid", Width = 550, Height = 60 }; grid.Children.Add(new ProgressBar { Name = $"{licence.GetLicenceLocatorToken()}progressBar", Value = 0, Height = 60, Width = 550, Margin = marginSetting }); grid.Children.Add(new TextBlock { Name = $"{licence.GetLicenceLocatorToken()}progressBarTopText", HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Text = $"Starting download for {licence.Product} - {licence.Simulator}...", Height = 15, FontSize = 12, Margin = new Thickness(0, 0, 0, 30) }); grid.Children.Add(new TextBlock { Name = $"{licence.GetLicenceLocatorToken()}progressBarBottomText", HorizontalAlignment = HorizontalAlignment.Center, VerticalAlignment = VerticalAlignment.Center, Text = "0%", FontSize = 12, Height = 15 }); downloadsPanel.Children.Add(grid); } // Fire off the tasks. _ = licencesForProductsToDownload.Select(productLicence => downloader.DownloadProductAsync(productLicence)).ToArray(); }