public static void AddControlAtGrid(Grid panel, UIElement control) { var compositeEditor = control as ICompositeEditor; if (panel == null) { return; } //add empty space row panel.RowDefinitions.Add(new RowDefinition { Height = new GridLength(SpaceRow) }); //add current row panel.RowDefinitions.Add(new RowDefinition { Height = GridLength.Auto }); var indexRow = panel.RowDefinitions.Count - 1; if (compositeEditor == null) { control.SetValue(Grid.RowProperty, indexRow); control.SetValue(Grid.ColumnProperty, 0); control.SetValue(Grid.ColumnSpanProperty, panel.ColumnDefinitions.Count - 1); panel.Add(control); return; } var editor = control as IPropertyEditor; var labelElement = editor != null && !string.IsNullOrEmpty(editor.Label) ? compositeEditor.LabelElement : null; var contentElement = compositeEditor.ContentElement; var additionalElement = compositeEditor.AdditionalElement; if (compositeEditor.DirectionLabelAndContent == DirectionLabelAndContent.Vertical) { var stackPanel = new StackPanel { Name = "StackPanelVerticalOrientation" }; stackPanel.SetValue(Grid.ColumnProperty, 0); stackPanel.SetValue(Grid.RowProperty, indexRow); stackPanel.SetValue(Grid.ColumnSpanProperty, 3); if (labelElement != null) { stackPanel.Add(labelElement); if (contentElement != null) { stackPanel.AddSpace(SpaceRow); } } if (contentElement != null) { stackPanel.Add(contentElement); if (additionalElement != null) { stackPanel.AddSpace(SpaceRow); } } if (additionalElement != null) { stackPanel.Add(additionalElement); } panel.Add(stackPanel); return; } if (compositeEditor.DirectionLabelAndContent == DirectionLabelAndContent.Horizontal) { if (labelElement != null) { labelElement.SetValue(VerticalAlignmentProperty, VerticalAlignment.Center); labelElement.SetValue(Grid.RowProperty, indexRow); labelElement.SetValue(Grid.ColumnProperty, 0); if (contentElement == null && additionalElement == null) { labelElement.SetValue(Grid.ColumnSpanProperty, 3); } if (contentElement == null && additionalElement != null) { labelElement.SetValue(Grid.ColumnSpanProperty, 2); } panel.Add(labelElement); } if (contentElement != null) { contentElement.SetValue(VerticalAlignmentProperty, VerticalAlignment.Center); contentElement.SetValue(Grid.RowProperty, indexRow); contentElement.SetValue(Grid.ColumnProperty, labelElement == null ? 0 : 1); if (labelElement == null && additionalElement == null) { contentElement.SetValue(Grid.ColumnSpanProperty, 3); } if (labelElement != null && additionalElement == null) { contentElement.SetValue(Grid.ColumnSpanProperty, 2); } panel.Add(contentElement); } if (additionalElement != null) { additionalElement.SetValue(VerticalAlignmentProperty, VerticalAlignment.Center); additionalElement.SetValue(Grid.RowProperty, indexRow); if (labelElement == null && contentElement == null) { additionalElement.SetValue(Grid.ColumnProperty, 0); additionalElement.SetValue(Grid.ColumnSpanProperty, 3); } if (labelElement != null && contentElement == null) { additionalElement.SetValue(Grid.ColumnProperty, 1); additionalElement.SetValue(Grid.ColumnSpanProperty, 2); } if (labelElement != null && contentElement != null) { additionalElement.SetValue(Grid.ColumnProperty, 2); } panel.Add(additionalElement); } if (contentElement != null && (int)contentElement.GetValue(Grid.ColumnProperty) > 0) { contentElement.Margin = DefaultMarginNextColumn; } if (additionalElement != null && (int)additionalElement.GetValue(Grid.ColumnProperty) > 0) { additionalElement.Margin = DefaultMarginNextColumn; } return; } }