PriorityGrid: flattening, priority and hierarchy sorting, nullable types, search bar hiding and fixes
I know this is a huge PR making it harder to review but still wanted to contribute the changes in one row because there is some overlapping stuff.
This PR introduces the following new features to the PropertyGrid:
- Unknown type flattening
- Default sorting mode
- HierarchyLevelAttribute added
- Sorting by hierarchy level
- PriorityAttribute added #885
- Sorting by priority #885
- NecessaryAttribute added
- Hide Search bar #497 (1)
- Nullable types support #819
- Support for overriding GroupHeaderTemplate and GroupHeaderMargin
This PR changes the following:
- TextBox instead of TextBlock as title element
- Enum type editor now uses and favors existing enum entry descriptions. Note: I took this code from another PR or commit somewhere here in this Github repo. I cannot remember where exactly and couldn't find the original posting, so please adjust if you know who provided this code originally. But it was such a useful contribution that I needed to include it (though slightly modified).
This PR fixes the following bugs:
- Search is not case insensitive #828
- Clients can now subclass PropertyGrid #812
Unknown type flattening
Types which do not have a known type editor are usually shown as a ReadOnlyTextBox which is inappropriate for almost any complex type. One could write an own custom editor but that's not always desired or possible.
This PR introduces flattening of "unknown" types (unknown as in no type editor available). Child type properties are browsed and flattened into the highest level as if their properties belonged in the class that is currently handled by the PropertyGrid. Furthermore some flattening options are available to decide in which category to place the flattened properties and how to name that category.
Flattening options:
- Off No flattening applied. Same behavior as before. [Default]
- Uncategorized: properties are categorized into the default category
- ParentCategory: child properties are placed into the category assigned to the parent property (i.e. via CategoryAttribute)
- ParentNameAsCategory: child properties are placed into a category named after the parent
While the flattening is off by default to keep the default behavior, the demo has been extented to apply flattening.
Here is the result of Flattening.ParentNameAsCategory with the PropertyGrid demo model.


Hide Search Bar
This Introduces a dependency property ShowSearchBar in order to hide the search bar.
The search bar XAML mark up has been updated to adjust the visibility accordingly.
Furthermore, multibinding is used to collapse the dockpanel visbility if the search bar and the sort buttons are both hidden.
To support that the BooleanArr2VisibilityConverter has been extented to optionally return a visible state if any of the bindings are visible (instead of all). For that the ConverterParameter can pass "UseAny"
Only show sort buttons, i.e. ShowSearchBar="False" ShowSortButton="True"

Collapsed Dock Panel if all hidden, i.e. ShowSearchBar="False" ShowSortButton="False"

Default Sorting Mode
This Introduces a dependency property DefaultSorting and enum SortingMode in order to set the default sorting mode.
Use DefaultSorting="Category"
SortingMode options
- Category
- Name
- HierarchyLevel
Sorting by hierarchy level
This is a flattening related sorting mode. If an unknown type is flattened, its properties are one hierarchy level deeper.

The sorting mode allows to have deeper level properties be ordered after all higher level properties.

The hierarchy level can be explicitly set by using the added HierarchyLevelAttribute on any property. The input value is an integer describing the hierarchy level of that property.
Sorting by priority
This uses the added PriorityAttribute to allow explicit order of property items.
By default all items are assumed to have a priority of 0 and will be sorted just as before by the main sorting modes (category, name, hierarchy level).
By adding a [Priority(1)] to a property, this will order that property to the top of the sorting chain, before all properties with a priority < 1.

TextBox instead of TextBlock as Title
The PropertyGridBaseStyle has been changed to use a TextBox instead of a TextBlock for the Title element.
This allows to support the hc:TitleElement.Necessary attached property. An according dependency property for IsNecessary was added to the PropertyItem which value is resolved by the PropertyResolver using the added NecessaryAttribute.
So by adding [Necessary] to a property, this will show the required field symbol. Here is an example:

I noticed that your previous pr contained the following string: 'Copyright (C) Xion GmbH', so I would like to ask is there a copyright problem with these code?
This was the default template of the company I am working at, whenever I create a new file this header is auto-added. Being in pandemic home office, this also applies at home. I simply forgot to remove them from the aforementioned files for the former pr. This PR should be clean.
None of this code is related in any way to the company I work at. I am personally contributing to this public repo of HandyControl, with useful general purpose features. None of the code in this pr is copyrighted and can be happily added to HandyControl
I currently reference my fork branch at work as I use it in production for one of our inhouse tools. We have a lot more features and extensions implemented at work for the PropertyGrid though, which I cannot share of course because that is property of the company I work at.
Is there any reason to not merge this? @NaBian
PR Issue: Button Colour Mismatch on Dark Theme:
