private void PopulateSoftwareGrid() { foreach (Software software in App.SoftwareList) { int newRowIndex = SoftwareGrid.RowDefinitions.Count; SoftwareGrid.RowDefinitions.Add(new RowDefinition() { Height = GridLength.Auto }); AddTextCell(software.Name, newRowIndex, 0, software.UpdateAvailable() ? Colors.Green : App.GetDefaultTextColor(), false); string installedText = software.InstalledVersion; Color installedColor = App.GetDefaultTextColor(); if (software.HasInstalledError()) { installedText = software.InstalledError; installedColor = Colors.Red; } else if (software.UpdateAvailable()) { installedColor = Colors.Green; } AddTextCell(installedText, newRowIndex, 1, installedColor, true); string latestText = software.LatestVersion; Color latestColor = App.GetDefaultTextColor(); if (software.HasLatestError()) { latestText = software.LatestError; latestColor = Colors.Red; } else if (software.UpdateAvailable()) { latestColor = Colors.Green; } AddTextCell(latestText, newRowIndex, 2, latestColor, true); ActionsCell actions = new ActionsCell(newRowIndex) { Tag = newRowIndex.ToString() }; SoftwareGrid.Children.Add(actions); Grid.SetRow(actions, newRowIndex); Grid.SetColumn(actions, 3); } }
private async void RefreshAllButton_Click(object sender, RoutedEventArgs e) { RefreshAllButton.IsEnabled = false; RefreshAllLoadingSpinner.IsActive = true; Task[] tasks = new Task[SoftwareGrid.RowDefinitions.Count - 1]; // do not include first "header" row for (int i = 0; i < tasks.Length; i++) { int localIndex = i; // i would get incremented for all inside the RunTaskAsync anonymous function tasks[localIndex] = CoreWindow.GetForCurrentThread().Dispatcher.RunTaskAsync(async() => { ActionsCell actions = GetGridCellOfType(SoftwareGrid, localIndex + 1, 3, typeof(ActionsCell)) as ActionsCell; await actions.Refresh(); }); } await Task.WhenAll(tasks); RefreshAllLoadingSpinner.IsActive = false; RefreshAllButton.IsEnabled = true; }
public async Task RemoveSoftware(int row) { SoftwareLoading.IsActive = true; Message.Text = ""; try { await App.Current.RemoveSoftware(App.SoftwareList[row - 1]); List <FrameworkElement> cellsToRemove = new List <FrameworkElement>(); foreach (FrameworkElement cell in SoftwareGrid.Children) { if (Grid.GetRow(cell) == row) { cellsToRemove.Add(cell); } } foreach (FrameworkElement cell in cellsToRemove) { SoftwareGrid.Children.Remove(cell); } foreach (FrameworkElement cell in SoftwareGrid.Children) { if (Grid.GetRow(cell) > row) { Grid.SetRow(cell, Grid.GetRow(cell) - 1); } } SoftwareGrid.RowDefinitions.RemoveAt(row); int rowCount = SoftwareGrid.RowDefinitions.Count; for (int i = row; i < rowCount; i++) { ActionsCell actions = GetGridCellOfType(SoftwareGrid, i, 3, typeof(ActionsCell)) as ActionsCell; actions.SetRow(actions.Row - 1); } } catch (Exception ex) { Message.Foreground = new SolidColorBrush(Colors.Red); Message.Text = ex.Message; } SoftwareLoading.IsActive = false; }