/// <summary> /// Creates the controls. /// </summary> /// <param name="instance"> /// The instance. /// </param> /// <param name="items"> /// The items. /// </param> public virtual void CreateControls(object instance, IEnumerable<PropertyItem> items) { if (this.tabControl == null) { return; } this.tabControl.Items.Clear(); this.panelControl.Children.Clear(); if (this.UseTabs) { this.tabControl.DataContext = instance; } else { this.panelControl.DataContext = instance; } this.tabControl.Visibility = this.UseTabs ? Visibility.Visible : Visibility.Hidden; this.scrollViewer.Visibility = !this.UseTabs ? Visibility.Visible : Visibility.Hidden; if (items == null) { return; } HeaderedContentControl group = null; string currentTab = null; string currentCategory = null; StackPanel categoryItems = null; Panel tabItems = null; double maxLabelWidth = this.MinimumLabelWidth; foreach (var pi in items) { if (currentTab == null || !currentTab.Equals(pi.Tab)) { tabItems = new StackPanel(); if (this.UseTabs) { var scroller = new ScrollViewer { VerticalScrollBarVisibility = ScrollBarVisibility.Auto, Content = tabItems }; var tab = new TabItem { Header = pi.Tab, Content = scroller }; if (this.TabHeaderTemplate != null) { tab.Header = new HeaderViewModel { Header = pi.Tab, Icon = pi.TabIcon }; tab.HeaderTemplate = this.TabHeaderTemplate; } this.tabControl.Items.Add(tab); } else { this.panelControl.Children.Add(tabItems); } if (this.TabPageHeaderTemplate != null) { var hc = new ContentControl { ContentTemplate = this.TabPageHeaderTemplate, Content = new HeaderViewModel { Header = pi.Tab, Description = pi.TabDescription, Icon = pi.TabIcon } }; tabItems.Children.Add(hc); } currentTab = pi.Tab; currentCategory = null; } if (currentCategory == null || !currentCategory.Equals(pi.Category)) { categoryItems = new StackPanelEx(); switch (this.CategoryControlType) { case CategoryControlType.GroupBox: group = new GroupBox { Margin = new Thickness(0, 4, 0, 4) }; break; case CategoryControlType.Expander: group = new Expander { IsExpanded = currentCategory == null }; break; case CategoryControlType.Template: group = new HeaderedContentControl { Template = this.CategoryControlTemplate }; break; } if (group != null) { if (this.CategoryHeaderTemplate != null) { group.HeaderTemplate = this.CategoryHeaderTemplate; group.Header = new HeaderViewModel { Header = pi.Category, Description = pi.CategoryDescription, Icon = pi.CategoryIcon }; } else { group.Header = pi.Category; } // Hide the group control if all child properties are invisible. group.SetBinding( VisibilityProperty, new Binding("VisibleChildrenCount") { Source = categoryItems, Converter = ZeroToVisibilityConverter }); group.Content = categoryItems; tabItems.Children.Add(group); } currentCategory = pi.Category; } // create the property panel (label, tooltip icon and property control) var propertyPanel = this.CreatePropertyPanel(pi, instance, ref maxLabelWidth); categoryItems.Children.Add(propertyPanel); } // set the label width to the calculated max label width this.ActualLabelWidth = maxLabelWidth; int index = this.tabControl.SelectedIndex; if (index >= this.tabControl.Items.Count || (uint)index == 0xffffffff) { index = 0; } if (this.tabControl.Items.Count > 0) { this.tabControl.SelectedItem = this.tabControl.Items[index]; } }
/// <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 controls. /// </summary> /// <param name="instance"> /// The instance. /// </param> /// <param name="items"> /// The items. /// </param> public virtual void CreateControls(object instance, IEnumerable <PropertyItem> items) { if (this.tabControl == null) { return; } this.tabControl.Items.Clear(); this.panelControl.Children.Clear(); if (this.UseTabs) { this.tabControl.DataContext = instance; } else { this.panelControl.DataContext = instance; } this.tabControl.Visibility = this.UseTabs ? Visibility.Visible : Visibility.Hidden; this.scrollViewer.Visibility = !this.UseTabs ? Visibility.Visible : Visibility.Hidden; if (items == null) { return; } HeaderedContentControl group = null; string currentTab = null; string currentCategory = null; StackPanel categoryItems = null; Panel tabItems = null; double maxLabelWidth = this.MinimumLabelWidth; foreach (var pi in items) { if (currentTab == null || !currentTab.Equals(pi.Tab)) { tabItems = new StackPanel(); if (this.UseTabs) { var scroller = new ScrollViewer { VerticalScrollBarVisibility = ScrollBarVisibility.Auto, Content = tabItems }; var tab = new TabItem { Header = pi.Tab, Content = scroller }; if (this.TabHeaderTemplate != null) { tab.Header = new HeaderViewModel { Header = pi.Tab, Icon = pi.TabIcon }; tab.HeaderTemplate = this.TabHeaderTemplate; } this.tabControl.Items.Add(tab); } else { this.panelControl.Children.Add(tabItems); } if (this.TabPageHeaderTemplate != null) { var hc = new ContentControl { ContentTemplate = this.TabPageHeaderTemplate, Content = new HeaderViewModel { Header = pi.Tab, Description = pi.TabDescription, Icon = pi.TabIcon } }; tabItems.Children.Add(hc); } currentTab = pi.Tab; currentCategory = null; } if (currentCategory == null || !currentCategory.Equals(pi.Category)) { categoryItems = new StackPanelEx(); switch (this.CategoryControlType) { case CategoryControlType.GroupBox: group = new GroupBox { Margin = new Thickness(0, 4, 0, 4) }; break; case CategoryControlType.Expander: group = new Expander { IsExpanded = currentCategory == null }; break; case CategoryControlType.Template: group = new HeaderedContentControl { Template = this.CategoryControlTemplate }; break; } if (group != null) { if (this.CategoryHeaderTemplate != null) { group.HeaderTemplate = this.CategoryHeaderTemplate; group.Header = new HeaderViewModel { Header = pi.Category, Description = pi.CategoryDescription, Icon = pi.CategoryIcon }; } else { group.Header = pi.Category; } // Hide the group control if all child properties are invisible. group.SetBinding( VisibilityProperty, new Binding("VisibleChildrenCount") { Source = categoryItems, Converter = ZeroToVisibilityConverter }); group.Content = categoryItems; tabItems.Children.Add(group); } currentCategory = pi.Category; } // create the property panel (label, tooltip icon and property control) var propertyPanel = this.CreatePropertyPanel(pi, instance, ref maxLabelWidth); categoryItems.Children.Add(propertyPanel); } // set the label width to the calculated max label width this.ActualLabelWidth = maxLabelWidth; int index = this.tabControl.SelectedIndex; if (index >= this.tabControl.Items.Count || (uint)index == 0xffffffff) { index = 0; } if (this.tabControl.Items.Count > 0) { this.tabControl.SelectedItem = this.tabControl.Items[index]; } }