Skip to content

Instantly share code, notes, and snippets.

@mwisnicki
Created February 11, 2012 01:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mwisnicki/1795111 to your computer and use it in GitHub Desktop.
Save mwisnicki/1795111 to your computer and use it in GitHub Desktop.
Using Grid for layout of PropertyControl
diff -r 0ea90643ac5a -r 61278776d28c Source/PropertyTools.Wpf/PropertyControl/PropertyControl.cs
--- a/Source/PropertyTools.Wpf/PropertyControl/PropertyControl.cs Fri Feb 03 13:45:59 2012 +0100
+++ b/Source/PropertyTools.Wpf/PropertyControl/PropertyControl.cs Fri Feb 10 16:58:49 2012 +0100
@@ -939,12 +939,19 @@
group.Content = categoryItems;
tabItems.Children.Add(group);
}
-
+ var propertyGrid = new Grid();
+ Grid.SetIsSharedSizeScope(propertyGrid, true);
+ categoryItems.Children.Add(propertyGrid);
+ var propertyIndex = 0;
foreach (var pi in g.Properties)
{
+ pi.SortIndex = propertyIndex;
// create the property panel (label, tooltip icon and property control)
var propertyPanel = this.CreatePropertyPanel(pi, instance, ref maxLabelWidth);
- categoryItems.Children.Add(propertyPanel);
+ propertyGrid.RowDefinitions.Add(new RowDefinition());
+ Grid.SetRow(propertyPanel, propertyIndex);
+ propertyGrid.Children.Add(propertyPanel);
+ propertyIndex++;
}
}
}
@@ -1142,7 +1149,13 @@
/// </returns>
private UIElement CreatePropertyPanel(PropertyItem pi, object instance, ref double maxLabelWidth)
{
- var propertyPanel = new DockPanel { Margin = new Thickness(2) };
+ var propertyPanel = new Grid {Margin = new Thickness(2) };
+ propertyPanel.ColumnDefinitions.Add(new System.Windows.Controls.ColumnDefinition
+ {
+ SharedSizeGroup = "labelColumn",
+ Width = GridLength.Auto
+ });
+ propertyPanel.ColumnDefinitions.Add(new System.Windows.Controls.ColumnDefinition());
var propertyLabel = this.CreateLabel(pi);
var propertyControl = this.CreatePropertyControl(pi);
if (propertyControl != null)
@@ -1291,10 +1304,18 @@
break;
}
+ if (propertyLabel != null)
+ {
+ Grid.SetColumn(propertyLabel, 0);
+ Grid.SetRow(propertyLabel, pi.SortIndex);
+ }
+
// add the property control
if (propertyControl != null)
{
propertyPanel.Children.Add(propertyControl);
+ Grid.SetColumn(propertyControl, 1);
+ Grid.SetRow(propertyControl, pi.SortIndex);
}
if (pi.IsEnabledDescriptor != null)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment