/// <summary> /// Creates visual grid object for module and adds it to expander /// </summary> /// <param name="expanderName"></param> /// <param name="module"></param> /// <param name="color"></param> private void AppendSidebarModule(string expanderName, BaseModule module, Color color) { logger.Trace($"Adding Module: {module.DisplayName} to Expander: {expanderName}"); // Add module to expander var expander = (Expander)this.FindName(expanderName); Grid itemGrid = new Grid(); itemGrid.Background = new SolidColorBrush(color); itemGrid.HorizontalAlignment = HorizontalAlignment.Stretch; ColumnDefinition iconColumn = new ColumnDefinition(); iconColumn.Width = GridLength.Auto; itemGrid.ColumnDefinitions.Add(iconColumn); ColumnDefinition nameColumn = new ColumnDefinition(); nameColumn.Width = GridLength.Auto; itemGrid.ColumnDefinitions.Add(nameColumn); RowDefinition row = new RowDefinition(); row.Height = GridLength.Auto; itemGrid.RowDefinitions.Add(row); BitmapImage bmp = module.RetrieveBitmapIcon(); Image icon = new Image(); icon.Source = new TransformedBitmap(bmp, VisualHelper.GetImageScaleWithBounds(100, bmp) ); Grid.SetRow(icon, 0); Grid.SetColumn(icon, 0); icon.HorizontalAlignment = HorizontalAlignment.Center; icon.VerticalAlignment = VerticalAlignment.Center; itemGrid.Children.Add(icon); Label displayName = new Label(); displayName.Content = module.DisplayName; Grid.SetRow(displayName, 0); Grid.SetColumn(displayName, 1); displayName.HorizontalAlignment = HorizontalAlignment.Center; displayName.VerticalAlignment = VerticalAlignment.Center; itemGrid.Children.Add(displayName); ToolTip tooltip = new ToolTip(); tooltip.Content = module.GetToolTipDescription(); displayName.ToolTip = tooltip; icon.ToolTip = tooltip; logger.Trace($"Adding module to ModuleMap {module.DisplayName}"); ModuleMap.Add(module.DisplayName, module); if (expander.Content != null) { ((ListBox)expander.Content).Items.Add(itemGrid); } else { ListBox list = new ListBox(); list.Background = new SolidColorBrush(color); list.Items.Add(itemGrid); expander.Content = list; } expander.InvalidateVisual(); // Click and drag new module from left side-bar itemGrid.Tag = module; itemGrid.PreviewMouseLeftButtonDown += delegate(object sender, MouseButtonEventArgs e) { CreateModuleObject(module); }; }