void CreatePanels() { int nbPanels = _panel.MaxColumnByRowProperty * _panel.MaxRowProperty; int column = 0; int row = 0; bool rightDirection = true; for( int i = 0; i < nbPanels; i++ ) { DockPanel dp = new DockPanel(); dp.DataContext = _panel.Panels[i]; dp.SetBinding( DockPanel.BackgroundProperty, new Binding( "IsActive" ) { Converter = new BooleanToColor() } ); Grid.SetColumn( dp, column ); Grid.SetRow( dp, row ); SplitGrid.Children.Add( dp ); if( rightDirection ) column++; else column--; if( column >= _panel.MaxColumnByRowProperty && rightDirection ) { row++; column--; rightDirection = false; } else if( column == -1 && !rightDirection ) { row++; rightDirection = true; column++; } _dockPanels.Add( dp ); } }
/// <summary> /// Creates the property panel. /// </summary> /// <param name="pi"> /// The pi. /// </param> /// <param name="instance"> /// The instance. /// </param> /// <param name="maxLabelWidth"> /// Width of the max label. /// </param> /// <returns> /// The property panel. /// </returns> private UIElement CreatePropertyPanel(PropertyItem pi, object instance, ref double maxLabelWidth) { var propertyPanel = new DockPanel { Margin = new Thickness(2) }; var propertyLabel = this.CreateLabel(pi); var propertyControl = this.CreatePropertyControl(pi); if (propertyControl != null) { if (!double.IsNaN(pi.Width)) { propertyControl.Width = pi.Width; propertyControl.HorizontalAlignment = HorizontalAlignment.Left; } if (!double.IsNaN(pi.Height)) { propertyControl.Height = pi.Height; } if (!double.IsNaN(pi.MinimumHeight)) { propertyControl.MinHeight = pi.MinimumHeight; } if (!double.IsNaN(pi.MaximumHeight)) { propertyControl.MaxHeight = pi.MaximumHeight; } if (pi.IsOptional) { if (pi.OptionalDescriptor != null) { propertyControl.SetBinding(IsEnabledProperty, new Binding(pi.OptionalDescriptor.Name)); } else { propertyControl.SetBinding( IsEnabledProperty, new Binding(pi.Descriptor.Name) { Converter = NullToBoolConverter }); } } if (instance is IDataErrorInfo) { if (this.ValidationTemplate != null) { Validation.SetErrorTemplate(propertyControl, this.ValidationTemplate); } if (this.ValidationErrorStyle != null) { propertyControl.Style = this.ValidationErrorStyle; } var errorControl = new ContentControl { ContentTemplate = this.ValidationErrorTemplate }; errorControl.SetBinding( VisibilityProperty, new Binding("(Validation.HasError)") { Source = propertyControl, Converter = BoolToVisibilityConverter }); errorControl.SetBinding( ContentControl.ContentProperty, new Binding("(Validation.Errors)") { Source = propertyControl }); // replace the property control by a stack panel containig the property control and the error control. var sp = new StackPanel(); sp.VerticalAlignment = VerticalAlignment.Center; sp.Children.Add(propertyControl); sp.Children.Add(errorControl); propertyControl = sp; } } var actualHeaderPlacement = pi.HeaderPlacement; if (!this.ShowCheckBoxHeaders && propertyControl is CheckBox) { actualHeaderPlacement = HeaderPlacement.Collapsed; var cb = propertyControl as CheckBox; cb.Content = propertyLabel; propertyLabel = null; } switch (actualHeaderPlacement) { case HeaderPlacement.Hidden: { var labelPanel = new DockPanel(); labelPanel.SetBinding(MinWidthProperty, new Binding("ActualLabelWidth") { Source = this }); propertyPanel.Children.Add(labelPanel); break; } case HeaderPlacement.Collapsed: break; default: { // create the label panel var labelPanel = new DockPanel(); if (pi.HeaderPlacement == HeaderPlacement.Left) { DockPanel.SetDock(labelPanel, Dock.Left); labelPanel.SetBinding(MinWidthProperty, new Binding("ActualLabelWidth") { Source = this }); } else { DockPanel.SetDock(labelPanel, Dock.Top); } propertyPanel.Children.Add(labelPanel); if (propertyLabel != null) { DockPanel.SetDock(propertyLabel, Dock.Left); labelPanel.Children.Add(propertyLabel); } if (this.ShowDescriptionIcons && this.DescriptionIcon != null) { if (!string.IsNullOrWhiteSpace(pi.Description)) { var descriptionIconImage = new Image { Source = this.DescriptionIcon, Stretch = Stretch.None, Margin = new Thickness(0, 4, 4, 4), VerticalAlignment = VerticalAlignment.Top }; // RenderOptions.SetBitmapScalingMode(descriptionIconImage, BitmapScalingMode.NearestNeighbor); descriptionIconImage.HorizontalAlignment = this.DescriptionIconAlignment; labelPanel.Children.Add(descriptionIconImage); if (!string.IsNullOrWhiteSpace(pi.Description)) { descriptionIconImage.ToolTip = this.CreateToolTip(pi.Description); } } } else { labelPanel.ToolTip = this.CreateToolTip(pi.Description); } // measure the size of the label and tooltip icon labelPanel.Measure(new Size(this.ActualWidth, this.ActualHeight)); maxLabelWidth = Math.Max(maxLabelWidth, labelPanel.DesiredSize.Width); } break; } // add the property control if (propertyControl != null) { propertyPanel.Children.Add(propertyControl); } if (pi.IsEnabledDescriptor != null) { propertyPanel.SetBinding(IsEnabledProperty, new Binding(pi.IsEnabledDescriptor.Name)); } if (pi.IsVisibleDescriptor != null) { propertyPanel.SetBinding( VisibilityProperty, new Binding(pi.IsVisibleDescriptor.Name) { Converter = BoolToVisibilityConverter }); } return propertyPanel; }