Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,25 @@ public Flattening FlattenChildProperties
set => SetValue(FlattenChildPropertiesProperty, value);
}

public static readonly DependencyProperty GroupHeaderTemplateProperty = DependencyProperty.Register(
nameof(GroupHeaderTemplate), typeof(DataTemplate), typeof(PropertyGrid), new PropertyMetadata(default(DataTemplate)));

public DataTemplate GroupHeaderTemplate
{
get => (DataTemplate) GetValue(GroupHeaderTemplateProperty);
set => SetValue(GroupHeaderTemplateProperty, value);
}

public static readonly DependencyProperty GroupHeaderMarginProperty = DependencyProperty.Register(
nameof(GroupHeaderMargin), typeof(Thickness), typeof(PropertyGrid),
new FrameworkPropertyMetadata(new Thickness(0, 0, 0, 6), FrameworkPropertyMetadataOptions.AffectsMeasure));

public Thickness GroupHeaderMargin
{
get => (Thickness) GetValue(GroupHeaderMarginProperty);
set => SetValue(GroupHeaderMarginProperty, value);
}

public override void OnApplyTemplate()
{
if (_searchBar != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,33 +12,33 @@ public class PropertyResolver
{
private static readonly Dictionary<Type, EditorTypeCode> TypeCodeDic = new Dictionary<Type, EditorTypeCode>
{
[typeof(string)] = EditorTypeCode.PlainText,
[typeof(sbyte)] = EditorTypeCode.SByteNumber,
[typeof(byte)] = EditorTypeCode.ByteNumber,
[typeof(short)] = EditorTypeCode.Int16Number,
[typeof(ushort)] = EditorTypeCode.UInt16Number,
[typeof(int)] = EditorTypeCode.Int32Number,
[typeof(uint)] = EditorTypeCode.UInt32Number,
[typeof(long)] = EditorTypeCode.Int64Number,
[typeof(ulong)] = EditorTypeCode.UInt64Number,
[typeof(float)] = EditorTypeCode.SingleNumber,
[typeof(double)] = EditorTypeCode.DoubleNumber,
[typeof(bool)] = EditorTypeCode.Switch,
[typeof(DateTime)] = EditorTypeCode.DateTime,
[typeof(string)] = EditorTypeCode.PlainText,
[typeof(sbyte)] = EditorTypeCode.SByteNumber,
[typeof(byte)] = EditorTypeCode.ByteNumber,
[typeof(short)] = EditorTypeCode.Int16Number,
[typeof(ushort)] = EditorTypeCode.UInt16Number,
[typeof(int)] = EditorTypeCode.Int32Number,
[typeof(uint)] = EditorTypeCode.UInt32Number,
[typeof(long)] = EditorTypeCode.Int64Number,
[typeof(ulong)] = EditorTypeCode.UInt64Number,
[typeof(float)] = EditorTypeCode.SingleNumber,
[typeof(double)] = EditorTypeCode.DoubleNumber,
[typeof(bool)] = EditorTypeCode.Switch,
[typeof(DateTime)] = EditorTypeCode.DateTime,
[typeof(HorizontalAlignment)] = EditorTypeCode.HorizontalAlignment,
[typeof(VerticalAlignment)] = EditorTypeCode.VerticalAlignment,
[typeof(ImageSource)] = EditorTypeCode.ImageSource
[typeof(VerticalAlignment)] = EditorTypeCode.VerticalAlignment,
[typeof(ImageSource)] = EditorTypeCode.ImageSource
};

public string ResolveCategory(PropertyDescriptor propertyDescriptor)
{
var categoryAttribute = propertyDescriptor.Attributes.OfType<CategoryAttribute>().FirstOrDefault();

return categoryAttribute == null ?
Lang.Miscellaneous :
string.IsNullOrEmpty(categoryAttribute.Category) ?
Lang.Miscellaneous :
categoryAttribute.Category;
if (categoryAttribute == null || string.IsNullOrEmpty(categoryAttribute.Category))
{
return Lang.Miscellaneous;
}
return categoryAttribute.Category;
}

public int? ResolveHierarchyLevel(PropertyDescriptor propertyDescriptor)
Expand Down Expand Up @@ -84,41 +84,41 @@ public PropertyEditorBase ResolveEditor(PropertyDescriptor propertyDescriptor)

public virtual PropertyEditorBase CreateDefaultEditor(Type type)
{
var underlyingType = Nullable.GetUnderlyingType(type);
if (underlyingType is not null)
if (!PropertyResolver.IsKnownEditorType(ref type))
{
type = underlyingType;
return new ReadOnlyTextPropertyEditor();
}
if (type.IsSubclassOf(typeof(Enum)))
{
return (PropertyEditorBase) new EnumPropertyEditor();
}

return TypeCodeDic.TryGetValue(type, out var editorType)
? editorType switch
{
EditorTypeCode.PlainText => new PlainTextPropertyEditor(),
EditorTypeCode.SByteNumber => new NumberPropertyEditor(sbyte.MinValue, sbyte.MaxValue),
EditorTypeCode.ByteNumber => new NumberPropertyEditor(byte.MinValue, byte.MaxValue),
EditorTypeCode.Int16Number => new NumberPropertyEditor(short.MinValue, short.MaxValue),
EditorTypeCode.UInt16Number => new NumberPropertyEditor(ushort.MinValue, ushort.MaxValue),
EditorTypeCode.Int32Number => new NumberPropertyEditor(int.MinValue, int.MaxValue),
EditorTypeCode.UInt32Number => new NumberPropertyEditor(uint.MinValue, uint.MaxValue),
EditorTypeCode.Int64Number => new NumberPropertyEditor(long.MinValue, long.MaxValue),
EditorTypeCode.UInt64Number => new NumberPropertyEditor(ulong.MinValue, ulong.MaxValue),
EditorTypeCode.SingleNumber => new NumberPropertyEditor(float.MinValue, float.MaxValue),
EditorTypeCode.DoubleNumber => new NumberPropertyEditor(double.MinValue, double.MaxValue),
EditorTypeCode.Switch => new SwitchPropertyEditor(),
EditorTypeCode.DateTime => new DateTimePropertyEditor(),
EditorTypeCode.HorizontalAlignment => new HorizontalAlignmentPropertyEditor(),
EditorTypeCode.VerticalAlignment => new VerticalAlignmentPropertyEditor(),
EditorTypeCode.ImageSource => new ImagePropertyEditor(),
_ => new ReadOnlyTextPropertyEditor()
}
: type.IsSubclassOf(typeof(Enum))
? (PropertyEditorBase) new EnumPropertyEditor()
: new ReadOnlyTextPropertyEditor();
return TypeCodeDic[type] switch
{
EditorTypeCode.PlainText => new PlainTextPropertyEditor(),
EditorTypeCode.SByteNumber => new NumberPropertyEditor(sbyte.MinValue, sbyte.MaxValue),
EditorTypeCode.ByteNumber => new NumberPropertyEditor(byte.MinValue, byte.MaxValue),
EditorTypeCode.Int16Number => new NumberPropertyEditor(short.MinValue, short.MaxValue),
EditorTypeCode.UInt16Number => new NumberPropertyEditor(ushort.MinValue, ushort.MaxValue),
EditorTypeCode.Int32Number => new NumberPropertyEditor(int.MinValue, int.MaxValue),
EditorTypeCode.UInt32Number => new NumberPropertyEditor(uint.MinValue, uint.MaxValue),
EditorTypeCode.Int64Number => new NumberPropertyEditor(long.MinValue, long.MaxValue),
EditorTypeCode.UInt64Number => new NumberPropertyEditor(ulong.MinValue, ulong.MaxValue),
EditorTypeCode.SingleNumber => new NumberPropertyEditor(float.MinValue, float.MaxValue),
EditorTypeCode.DoubleNumber => new NumberPropertyEditor(double.MinValue, double.MaxValue),
EditorTypeCode.Switch => new SwitchPropertyEditor(),
EditorTypeCode.DateTime => new DateTimePropertyEditor(),
EditorTypeCode.HorizontalAlignment => new HorizontalAlignmentPropertyEditor(),
EditorTypeCode.VerticalAlignment => new VerticalAlignmentPropertyEditor(),
EditorTypeCode.ImageSource => new ImagePropertyEditor(),
_ => new ReadOnlyTextPropertyEditor()
};
}

public virtual PropertyEditorBase CreateEditor(Type type) => Activator.CreateInstance(type) as PropertyEditorBase ?? new ReadOnlyTextPropertyEditor();
public virtual PropertyEditorBase CreateEditor(Type type) =>
Activator.CreateInstance(type) as PropertyEditorBase ?? new ReadOnlyTextPropertyEditor();

public static bool IsKnownEditorType(Type type)
public static bool IsKnownEditorType(ref Type type)
{
var underlyingType = Nullable.GetUnderlyingType(type);
if (underlyingType is not null)
Expand All @@ -129,6 +129,8 @@ public static bool IsKnownEditorType(Type type)
return TypeCodeDic.ContainsKey(type) || type.IsSubclassOf(typeof(Enum));
}

public static bool IsKnownEditorType(Type type) => IsKnownEditorType(ref type);

private enum EditorTypeCode
{
PlainText,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,12 +117,12 @@
</Style>

<Style x:Key="PropertyGroupItemBaseStyle" TargetType="GroupItem">
<Setter Property="Margin" Value="0,0,0,6"/>
<Setter Property="Padding" Value="10,6,6,0"/>
<Setter Property="Margin" Value="{Binding Path=GroupHeaderMargin, RelativeSource={RelativeSource AncestorType={x:Type hc:PropertyGrid}, Mode=FindAncestor}, FallbackValue='0,0,0,6'}" />
<Setter Property="Padding" Value="10,6,6,0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupItem">
<Expander Header="{Binding Name}" IsExpanded="True">
<Expander Header="{Binding Name}" IsExpanded="True" HeaderTemplate="{Binding Path=GroupHeaderTemplate, RelativeSource={RelativeSource AncestorType={x:Type hc:PropertyGrid}, Mode=FindAncestor}}">
<Border BorderThickness="1,0,1,1" BorderBrush="{DynamicResource BorderBrush}" Background="{DynamicResource RegionBrush}" CornerRadius="0,0,4,4">
<ItemsPresenter Margin="{TemplateBinding Padding}"/>
</Border>
Expand Down
4 changes: 2 additions & 2 deletions src/Shared/HandyControl_Shared/Themes/Theme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -9772,12 +9772,12 @@
</Style.Triggers>
</Style>
<Style x:Key="PropertyGroupItemBaseStyle" TargetType="GroupItem">
<Setter Property="Margin" Value="0,0,0,6" />
<Setter Property="Margin" Value="{Binding Path=GroupHeaderMargin, RelativeSource={RelativeSource AncestorType={x:Type hc:PropertyGrid}, Mode=FindAncestor}, FallbackValue='0,0,0,6'}" />
<Setter Property="Padding" Value="10,6,6,0" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupItem">
<Expander Header="{Binding Name}" IsExpanded="True">
<Expander Header="{Binding Name}" IsExpanded="True" HeaderTemplate="{Binding Path=GroupHeaderTemplate, RelativeSource={RelativeSource AncestorType={x:Type hc:PropertyGrid}, Mode=FindAncestor}}">
<Border BorderThickness="1,0,1,1" BorderBrush="{DynamicResource BorderBrush}" Background="{DynamicResource RegionBrush}" CornerRadius="0,0,4,4">
<ItemsPresenter Margin="{TemplateBinding Padding}" />
</Border>
Expand Down