/// <summary> /// Add an item to the progress /// </summary> /// <param name="itemName">The name of the item to add</param> /// <param name="maxProgress">Maximum value of progress</param> public void AddItem(string itemName, int maxProgress) { Grid g = new Grid(); ColumnDefinition cd0 = new ColumnDefinition(); cd0.Width = new GridLength(40, GridUnitType.Pixel); ColumnDefinition cd1 = new ColumnDefinition(); cd1.Width = new GridLength(0.5, GridUnitType.Star); ColumnDefinition cd2 = new ColumnDefinition(); cd2.Width = new GridLength(0.5, GridUnitType.Star); g.ColumnDefinitions.Add(cd0); g.ColumnDefinitions.Add(cd1); g.ColumnDefinitions.Add(cd2); Image image = new Image(); image.HorizontalAlignment = HorizontalAlignment.Left; image.VerticalAlignment = VerticalAlignment.Center; image.Stretch = System.Windows.Media.Stretch.Uniform; image.Width = 32; image.Height = 32; image.Source = new System.Windows.Media.Imaging.BitmapImage(SearchProviderFactory.GetLargeImage(itemName)); Grid.SetColumn(image, 0); TextBlock tbName = new TextBlock(); tbName.Text = itemName; tbName.VerticalAlignment = VerticalAlignment.Center; tbName.FontSize = 16; Grid.SetColumn(tbName, 1); ProgressBar pbProgress = new ProgressBar(); pbProgress.Minimum = 0; pbProgress.Maximum = maxProgress; pbProgress.Height = 30; Grid.SetColumn(pbProgress, 2); Rectangle rect = new Rectangle(); rect.Fill = new SolidColorBrush(Color.FromArgb(0x2F, 0x00, 0xFF, 0x00)); Grid.SetColumn(rect, 2); rect.Visibility = Visibility.Collapsed; rect.Margin = new Thickness(2); g.Children.Add(image); g.Children.Add(tbName); g.Children.Add(pbProgress); g.Children.Add(rect); g.Margin = new Thickness(0, 5, 0, 5); _progressItems.Add(itemName, pbProgress); _progressFinishedItems.Add(itemName, rect); progressItemsPanel.Children.Add(g); }
private void Repopulate() { panelGroups = new StackPanel(); panelGroups.Orientation = Orientation.Vertical; borderMain.Content = panelGroups; _allButtons = new List <ToggleButton>(); List <string> allGroups = SearchProviderFactory.GetGroups(); int maxGroupItems = 0; foreach (string group in allGroups) { TextBlock tbTitle = new TextBlock(); tbTitle.Text = CultureHelper.GetString(Properties.Resources.ResourceManager, "SEARCHGROUP" + group.ToUpper()); tbTitle.FontSize = 14; panelGroups.Children.Add(tbTitle); WrapPanel panelButtons = new WrapPanel(); panelButtons.Orientation = Orientation.Horizontal; panelGroups.Children.Add(panelButtons); List <string> typeNames = SearchProviderFactory.GetTypeNames(group); List <string> displayNames = SearchProviderFactory.GetDisplayNames(group); maxGroupItems = Math.Max(maxGroupItems, typeNames.Count); for (int i = 0; i < typeNames.Count; i++) { ToggleButton button = new ToggleButton(); button.Tag = typeNames[i]; button.Width = 70; button.Height = 70; button.Checked += new RoutedEventHandler(searchButton_Checked); button.Unchecked += new RoutedEventHandler(searchButton_Unchecked); StackPanel sp = new StackPanel(); Image image = new Image(); image.Width = 40; image.Height = 40; image.Stretch = System.Windows.Media.Stretch.Fill; image.Source = new BitmapImage(SearchProviderFactory.GetLargeImage(typeNames[i])); TextBlock tb = new TextBlock(); tb.Text = displayNames[i]; tb.HorizontalAlignment = HorizontalAlignment.Center; sp.Children.Add(image); sp.Children.Add(tb); button.Content = sp; panelButtons.Children.Add(button); _allButtons.Add(button); } } if (_allButtons.Count > 0) { _allButtons[0].IsChecked = true; } int columns = Math.Min(5, maxGroupItems); this.Width = (70 * columns) + 20; //this.Height = (Math.Ceiling((double)numItems / (double)columns) * 80) + 20; }