/// <summary> /// Creates the content control and property panel. /// </summary> /// <param name="g">The g.</param> /// <param name="tabItems">The tab items.</param> /// <param name="index">The index.</param> /// <param name="fillTab">Stretch the panel if set to <c>true</c>.</param> /// <returns> /// The property panel. /// </returns> private Panel CreatePropertyPanel(Group g, Grid tabItems, int index, bool fillTab) { if (fillTab) { var p = new Grid(); tabItems.Children.Add(p); Grid.SetRow(p, tabItems.RowDefinitions.Count); tabItems.RowDefinitions.Add( new System.Windows.Controls.RowDefinition { Height = new GridLength(1, GridUnitType.Star) }); return p; } var propertyPanel = new StackPanelEx(); HeaderedContentControl groupContentControl = null; switch (this.CategoryControlType) { case CategoryControlType.GroupBox: groupContentControl = new GroupBox { Margin = new Thickness(0, 4, 0, 4) }; break; case CategoryControlType.Expander: groupContentControl = new Expander { IsExpanded = index == 0 }; break; case CategoryControlType.Template: groupContentControl = new HeaderedContentControl { Template = this.CategoryControlTemplate, Focusable = false }; break; } if (groupContentControl != null) { if (this.CategoryHeaderTemplate != null) { groupContentControl.HeaderTemplate = this.CategoryHeaderTemplate; groupContentControl.Header = g; } else { groupContentControl.Header = g.Header; } // Hide the group control if all child properties are invisible. groupContentControl.SetBinding( UIElement.VisibilityProperty, new Binding("VisibleChildrenCount") { Source = propertyPanel, Converter = ZeroToVisibilityConverter }); if (this.LabelWidthSharing == LabelWidthSharing.SharedInGroup) { Grid.SetIsSharedSizeScope(propertyPanel, true); } groupContentControl.Content = propertyPanel; tabItems.Children.Add(groupContentControl); Grid.SetRow(groupContentControl, tabItems.RowDefinitions.Count); tabItems.RowDefinitions.Add(new System.Windows.Controls.RowDefinition { Height = GridLength.Auto }); } return propertyPanel; }
/// <summary> /// Creates the property model. /// </summary> /// <param name="instance"> /// The instance. /// </param> /// <param name="isEnumerable"> /// if set to <c>true</c> [is enumerable]. /// </param> /// <param name="options"> /// The options. /// </param> /// <returns> /// A list of <see cref="Tab"/> . /// </returns> public virtual IEnumerable<Tab> CreateModel(object instance, bool isEnumerable, IPropertyControlOptions options) { if (instance == null) { return null; } this.Reset(); var tabs = new Dictionary<string, Tab>(); foreach (var pi in this.CreatePropertyItems(instance, options).OrderBy(t => t.SortIndex)) { var tabHeader = pi.Tab ?? string.Empty; if (!tabs.ContainsKey(tabHeader)) { tabs.Add(tabHeader, new Tab { Header = pi.Tab }); } var tab = tabs[tabHeader]; var group = tab.Groups.FirstOrDefault(g => g.Header == pi.Category); if (group == null) { group = new Group { Header = pi.Category }; tab.Groups.Add(group); } group.Properties.Add(pi); } return tabs.Values.ToList(); }