Created
February 14, 2012 09:39
-
-
Save mwisnicki/1825361 to your computer and use it in GitHub Desktop.
Using Grid for layout of PropertyControl v2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff -r 0ea90643ac5a -r 468f9a9165a4 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 Mon Feb 13 12:16:16 2012 +0100 | |
@@ -161,6 +161,16 @@ | |
new FrameworkPropertyMetadata(0, FrameworkPropertyMetadataOptions.BindsTwoWayByDefault)); | |
/// <summary> | |
+ /// The shared size labels property. | |
+ /// </summary> | |
+ public static readonly DependencyProperty SharedSizeLabelsProperty = | |
+ DependencyProperty.Register( | |
+ "SharedSizeLabels", | |
+ typeof(bool), | |
+ typeof(PropertyControl), | |
+ new UIPropertyMetadata(true)); | |
+ | |
+ /// <summary> | |
/// The show check box headers property. | |
/// </summary> | |
public static readonly DependencyProperty ShowCheckBoxHeadersProperty = | |
@@ -603,6 +613,21 @@ | |
} | |
/// <summary> | |
+ /// Controls whether labels should have the same size. | |
+ /// </summary> | |
+ public bool SharedSizeLabels | |
+ { | |
+ get | |
+ { | |
+ return (bool)GetValue(SharedSizeLabelsProperty); | |
+ } | |
+ set | |
+ { | |
+ SetValue(SharedSizeLabelsProperty, value); | |
+ } | |
+ } | |
+ | |
+ /// <summary> | |
/// Gets or sets a value indicating whether to show check box headers. | |
/// </summary> | |
/// <value> | |
@@ -936,6 +961,7 @@ | |
Converter = ZeroToVisibilityConverter | |
}); | |
+ Grid.SetIsSharedSizeScope(categoryItems, true); | |
group.Content = categoryItems; | |
tabItems.Children.Add(group); | |
} | |
@@ -1125,6 +1151,27 @@ | |
return this.PropertyControlFactory.CreateControl(pi, options); | |
} | |
+ [ValueConversion(typeof(bool), typeof(string), ParameterType = typeof(string))] | |
+ class BoolToSizeGroupConverter : IValueConverter | |
+ { | |
+ public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) | |
+ { | |
+ var isSharedSize = (bool)value; | |
+ if (targetType == typeof(string)) | |
+ { | |
+ return isSharedSize ? (string)parameter : null; | |
+ } | |
+ return value; | |
+ } | |
+ | |
+ public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) | |
+ { | |
+ throw new NotImplementedException(); | |
+ } | |
+ } | |
+ | |
+ private static readonly BoolToSizeGroupConverter boolToSizeGroupConverter = new BoolToSizeGroupConverter(); | |
+ | |
/// <summary> | |
/// Creates the property panel. | |
/// </summary> | |
@@ -1142,7 +1189,23 @@ | |
/// </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) }; | |
+ var labelColumn = new System.Windows.Controls.ColumnDefinition | |
+ { | |
+ Width = GridLength.Auto | |
+ }; | |
+ labelColumn.SetBinding( | |
+ DefinitionBase.SharedSizeGroupProperty, | |
+ new Binding | |
+ { | |
+ Path = new PropertyPath(SharedSizeLabelsProperty), | |
+ Source = this, | |
+ Converter = boolToSizeGroupConverter, | |
+ ConverterParameter = "labelColumn" | |
+ }); | |
+ propertyPanel.ColumnDefinitions.Add(labelColumn); | |
+ propertyPanel.ColumnDefinitions.Add(new System.Windows.Controls.ColumnDefinition()); | |
+ propertyPanel.RowDefinitions.Add(new RowDefinition()); | |
var propertyLabel = this.CreateLabel(pi); | |
var propertyControl = this.CreatePropertyControl(pi); | |
if (propertyControl != null) | |
@@ -1210,6 +1273,7 @@ | |
sp.Children.Add(errorControl); | |
propertyControl = sp; | |
} | |
+ Grid.SetColumn(propertyControl, 1); | |
} | |
var actualHeaderPlacement = pi.HeaderPlacement; | |
@@ -1226,27 +1290,36 @@ | |
switch (actualHeaderPlacement) | |
{ | |
case HeaderPlacement.Hidden: | |
+ break; | |
+ | |
+ case HeaderPlacement.Collapsed: | |
{ | |
- var labelPanel = new DockPanel(); | |
- labelPanel.SetBinding(MinWidthProperty, new Binding("ActualLabelWidth") { Source = this }); | |
- propertyPanel.Children.Add(labelPanel); | |
+ if (propertyControl != null) | |
+ { | |
+ Grid.SetColumn(propertyControl, 0); | |
+ Grid.SetColumnSpan(propertyControl, 2); | |
+ } | |
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 | |
+ else // Above | |
{ | |
- DockPanel.SetDock(labelPanel, Dock.Top); | |
+ if (propertyControl != null) | |
+ { | |
+ propertyPanel.RowDefinitions.Add(new RowDefinition()); | |
+ Grid.SetColumnSpan(labelPanel, 2); | |
+ Grid.SetRow(propertyControl, 1); | |
+ Grid.SetColumn(propertyControl, 0); | |
+ Grid.SetColumnSpan(propertyControl, 2); | |
+ } | |
} | |
propertyPanel.Children.Add(labelPanel); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment