From bdbd98b09ec30d5e33afffaa0d1d828bdfc07672 Mon Sep 17 00:00:00 2001 From: brianlagunas_cp Date: Thu, 6 Oct 2011 21:57:37 +0000 Subject: [PATCH] PropertyGrid: fixed alignment of grid splitter for expanded properties --- .../ExpandableObjectMarginConverter.cs | 20 +++++ .../Implementation/PropertyGridUtilities.cs | 7 ++ .../Implementation/PropertyItem.cs | 25 ++++-- .../PropertyGrid/Themes/Generic.xaml | 87 +++---------------- .../WPFToolkit.Extended.csproj | 1 + 5 files changed, 60 insertions(+), 80 deletions(-) create mode 100644 ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Converters/ExpandableObjectMarginConverter.cs diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Converters/ExpandableObjectMarginConverter.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Converters/ExpandableObjectMarginConverter.cs new file mode 100644 index 00000000..8ae34007 --- /dev/null +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/Core/Converters/ExpandableObjectMarginConverter.cs @@ -0,0 +1,20 @@ +using System; +using System.Windows; +using System.Windows.Data; + +namespace Microsoft.Windows.Controls.Core.Converters +{ + public class ExpandableObjectMarginConverter : IValueConverter + { + public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + int childLevel = (int)value; + return new Thickness(childLevel * 15, 0, 0, 0); + } + + public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture) + { + throw new NotImplementedException(); + } + } +} diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGridUtilities.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGridUtilities.cs index f42b3e01..20c7cea1 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGridUtilities.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyGridUtilities.cs @@ -59,6 +59,13 @@ namespace Microsoft.Windows.Controls.PropertyGrid return descriptors; } + internal static PropertyItem CreatePropertyItem(PropertyDescriptor property, object instance, PropertyGrid grid, string bindingPath, int level) + { + PropertyItem item = CreatePropertyItem(property, instance, grid, bindingPath); + item.Level = level; + return item; + } + internal static PropertyItem CreatePropertyItem(PropertyDescriptor property, object instance, PropertyGrid grid, string bindingPath) { PropertyItem propertyItem = new PropertyItem(instance, property, grid, bindingPath); diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyItem.cs b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyItem.cs index 193b085c..7a7429ca 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyItem.cs +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Implementation/PropertyItem.cs @@ -1,13 +1,13 @@ using System; -using System.Linq; +using System.Collections.Generic; using System.ComponentModel; +using System.Linq; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Input; -using Microsoft.Windows.Controls.PropertyGrid.Commands; using System.Windows.Markup.Primitives; -using System.Collections.Generic; +using Microsoft.Windows.Controls.PropertyGrid.Commands; namespace Microsoft.Windows.Controls.PropertyGrid { @@ -187,9 +187,9 @@ namespace Microsoft.Windows.Controls.PropertyGrid #region IsReadOnly - public bool IsReadOnly - { - get { return PropertyDescriptor.IsReadOnly; } + public bool IsReadOnly + { + get { return PropertyDescriptor.IsReadOnly; } } #endregion //IsReadOnly @@ -218,6 +218,17 @@ namespace Microsoft.Windows.Controls.PropertyGrid #endregion //IsSelected + #region Level + + public static readonly DependencyProperty LevelProperty = DependencyProperty.Register("Level", typeof(int), typeof(PropertyItem), new UIPropertyMetadata(0)); + public int Level + { + get { return (int)GetValue(LevelProperty); } + set { SetValue(LevelProperty, value); } + } + + #endregion //Level + #region Properties public static readonly DependencyProperty PropertiesProperty = DependencyProperty.Register("Properties", typeof(PropertyItemCollection), typeof(PropertyItem), new UIPropertyMetadata(null)); @@ -387,7 +398,7 @@ namespace Microsoft.Windows.Controls.PropertyGrid foreach (PropertyDescriptor descriptor in descriptors) { if (descriptor.IsBrowsable) - propertyItems.Add(PropertyGridUtilities.CreatePropertyItem(descriptor, Instance, PropertyGrid, String.Format("{0}.{1}", BindingPath, descriptor.Name))); + propertyItems.Add(PropertyGridUtilities.CreatePropertyItem(descriptor, Instance, PropertyGrid, String.Format("{0}.{1}", BindingPath, descriptor.Name), Level + 1)); } } catch (Exception ex) diff --git a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Themes/Generic.xaml b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Themes/Generic.xaml index fd51ac1b..73a87005 100644 --- a/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Themes/Generic.xaml +++ b/ExtendedWPFToolkitSolution/Src/WPFToolkit.Extended/PropertyGrid/Themes/Generic.xaml @@ -13,6 +13,7 @@ + @@ -299,20 +300,26 @@ - - - + + + + + + + - + - + + - @@ -328,7 +335,7 @@ - + @@ -364,72 +371,6 @@ - -