Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PriorityGrid: flattening, priority and hierarchy sorting, nullable types, search bar hiding and fixes #892

Open
wants to merge 39 commits into
base: master
Choose a base branch
from

Conversation

SamirKharchi
Copy link

@SamirKharchi SamirKharchi commented Jul 2, 2021

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:

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:

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.

flattenedHierarchyModel
flattenedPropertyGridDemoModel

flattenedHierarchy

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"
hideSearchBar

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

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.
hierarchyLevelSorting

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

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.
priority01
priority02

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:
necessary

SamXion and others added 30 commits May 10, 2021 08:49
Types which do not have a known type editor are browsed and flattened into the highest level as if their properties belong in the class that is currently handled by the PropertyGrid.
Furthermore some flatting options are available to decide in which category to place the flattened properties and how to name that category.
While the flattening is off by default to keep the default behavior, the demo has been extented to do apply flattening.
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 be set to 'UseAny'.
…earch 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 be set to 'UseAny'.
Properties are ordered based on their level in the class hierarchy.
PropertyGrid: this introduces hierarchy level sorting (assumes flattening properties).
…refore elements were bound incorrectly and did not update the actual element values.

Also adds some instance data to the demo model.
PropertyGrid: Fixes that the root component is assigned to the PropertyItem
PropertyGrid: Fix custom editor support
…-Description

Enum type editor now uses and favors existing enum entry descriptions.
In default, set Window.SizeToContent to Width or Height or WidthAndHeight, when the content size changed, the window will not re-center to screen or owner. After add this attached property, it will auto re-center.
…ttached-property

Add KeepCenterOnSizeChanged attached property
Fixes a crash scenario when the enum was not set or null
Also fixes a bug when CraeteDefaultEditor was called (type was not referenced so it didn't update to be the underlying type).
Added support for GroupHeaderTemplate and GroupHeaderMargin
Sorting for priority, hierarchy level and default sorting mode added
PropertyGrid can now be derived from requiring only a simple style base definition on the client side
PropertyResolver now exposes more virtual functions to correctly use it for custom resolutions
Fixes a flattening issue when no editor attribute was used
Fixes search bar case sensitivity issue
@NaBian
Copy link
Member

NaBian commented Jul 10, 2021

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?

@SamirKharchi
Copy link
Author

SamirKharchi commented Jul 10, 2021

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.

@M0n7y5
Copy link
Contributor

M0n7y5 commented Dec 9, 2021

Is there any reason to not merge this? @NaBian

@Sewer56
Copy link

Sewer56 commented Dec 9, 2021

PR Issue: Button Colour Mismatch on Dark Theme:

Reloaded-II_u6C5fTzpzH

@ghost1372 ghost1372 added the 🏭 enhancement New feature or request label Dec 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🏭 enhancement New feature or request
Projects
Status: In Progress
Development

Successfully merging this pull request may close these issues.

6 participants