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
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
1be50e5
Introduces flattening of types without a known type editor.
SamXion May 10, 2021
6283977
removed unnecessary dependency
SamXion May 10, 2021
07da337
Merge branch 'HandyOrg:master' into Flattening-PropertyGrid
SamirKharchi May 10, 2021
b30c1c6
Hides the search bar element.
SamXion May 10, 2021
9d57852
Introduces a dependency property ShowSearchBar in order to hide the s…
SamXion May 10, 2021
3d1d1c8
Merge branch 'Hide-SearchBar' of https://github.com/SamirKharchi/Hand…
SamXion May 10, 2021
2fa58eb
Merge pull request #1 from SamirKharchi/Flattening-PropertyGrid
SamirKharchi May 10, 2021
4ce3526
Merge branch 'master' into Hide-SearchBar
SamirKharchi May 10, 2021
37e4326
Merge pull request #2 from SamirKharchi/Hide-SearchBar
SamirKharchi May 10, 2021
003af5e
This introduces hierarchy level sorting (assumes flattening properties).
SamXion May 10, 2021
858a410
Merge pull request #3 from SamirKharchi/Sort-By-Hierarchy
SamirKharchi May 10, 2021
c474be7
Fixes that the root component is assigned to the PropertyItem and the…
SamXion May 11, 2021
b028dbf
Merge branch 'master' into Flattening-PropertyGrid
SamirKharchi May 11, 2021
c4acbc2
Merge pull request #4 from SamirKharchi/Flattening-PropertyGrid
SamirKharchi May 11, 2021
b628b78
Adds support for nullable types
SamXion May 11, 2021
559cb81
Merge pull request #5 from SamirKharchi/Nullable-Types-Support
SamirKharchi May 11, 2021
b798e43
Fixes that custom editors are not correctly created.
SamXion May 11, 2021
14a0c8c
Merge pull request #6 from SamirKharchi/Fix-CustomEditor-Support
SamirKharchi May 11, 2021
c5b9c33
Enum type editor now uses and favors existing enum entry descriptions.
SamXion May 11, 2021
809386a
Merge pull request #7 from SamirKharchi/Improve-Enum-Display-By-Using…
SamirKharchi May 11, 2021
5c1f1db
See https://github.com/HandyOrg/HandyControl/pull/818
SamXion May 11, 2021
13a9a9f
Merge pull request #8 from SamirKharchi/Add-KeepCenterOnSizeChanged-a…
SamirKharchi May 11, 2021
5ed5fbf
Fixes a crash scenario when the enum was not set or null
SamXion May 11, 2021
f5811bd
Merge pull request #9 from SamirKharchi/Fix-Enum-Bug
SamirKharchi May 11, 2021
c9bb625
Added support for GroupHeaderTemplate and GroupHeaderMargin
SamXion May 12, 2021
2cefb58
Merge pull request #10 from SamirKharchi/Fix-Enum-Bug
SamirKharchi May 12, 2021
62fb546
Merge branch 'HandyOrg:master' into master
SamirKharchi Jun 3, 2021
9da7d34
Merge remote-tracking branch 'upstream/master'
SamirKharchi Jul 2, 2021
cfcb503
New sorting options and extentability
SamXion Jul 2, 2021
d558fac
Merge pull request #13 from SamirKharchi/FlatteingSortingExtentibility
SamirKharchi Jul 2, 2021
ff10175
revert unnecessary commit
SamirKharchi Jul 2, 2021
8c580cd
Revert wrong sync changes
SamirKharchi Jul 2, 2021
576e8bd
theme update
SamirKharchi Jul 2, 2021
9b5182f
Merge pull request #14 from SamirKharchi/FlatteingSortingExtentibility
SamirKharchi Jul 2, 2021
de587ed
Merge branch 'HandyOrg:master' into master
SamirKharchi Jul 4, 2021
64ccd9f
Merge branch 'HandyOrg:master' into master
SamirKharchi Jul 10, 2021
433347d
Fixes crash when adding items to a carousel that was not initialised …
SamirKharchi Jul 14, 2021
7931714
Merge pull request #15 from SamirKharchi/Fix-crash-when-post-adding-t…
SamirKharchi Jul 14, 2021
06a1fd1
Merge branch 'master' into master
SamirKharchi Nov 5, 2021
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
49 changes: 34 additions & 15 deletions src/Net_40/HandyControl_Net_40/Themes/Theme.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -699,8 +699,16 @@
<GeometryDrawing o:Freeze="True" Brush="#FF00529C" Geometry="F1M15,8L15,10 12,13 9,10 9,8 11,10 11,4 13,4 13,10z" />
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
<ItemsPanelTemplate x:Key="StepBarHorizontalItemsPanelTemplate">
</DrawingBrush>
<DrawingBrush x:Key="SortByHierarchyLevelDrawingBrush" o:Freeze="True">
<DrawingBrush.Drawing>
<DrawingGroup o:Freeze="True">
<GeometryDrawing o:Freeze="True" Brush="#FF000000" Geometry="F1 M470,470z M0,0z M346.494,283.658L346.494,358.951 296.758,358.951 296.758,283.658 245,283.658 245,186.343 296.758,186.343 296.758,0 173.242,0 173.242,186.343 225,186.343 225,283.658 173.242,283.658 173.242,358.951 123.516,358.951 123.516,283.658 0,283.658 0,470 123.516,470 123.516,378.951 173.242,378.951 173.242,470 296.758,470 296.758,378.951 346.494,378.951 346.494,470 470,470 470,283.658 346.494,283.658z M193.242,20L276.758,20 276.758,166.343 193.242,166.343 193.242,20z M103.516,450L20,450 20,303.658 103.516,303.658 103.516,450z M276.758,450L193.242,450 193.242,303.658 276.758,303.658 276.758,450z M450,450L366.494,450 366.494,303.658 450,303.658 450,450z" />
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>

<ItemsPanelTemplate x:Key="StepBarHorizontalItemsPanelTemplate">
<UniformGrid Rows="1" />
</ItemsPanelTemplate>
<ItemsPanelTemplate x:Key="StepBarVerticalItemsPanelTemplate">
Expand Down Expand Up @@ -9975,18 +9983,29 @@
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<DockPanel LastChildFill="True" Margin="0,0,0,6">
<hc:ButtonGroup Margin="0,0,6,0" Visibility="{Binding ShowSortButton,RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource Boolean2VisibilityConverter}}" Style="{StaticResource ButtonGroupSolid}">
<RadioButton Command="interactivity:ControlCommands.SortByCategory" IsChecked="True">
<Rectangle Width="16" Height="16" Fill="{StaticResource SortByCategoryDrawingBrush}" />
</RadioButton>
<RadioButton Command="interactivity:ControlCommands.SortByName">
<Rectangle Width="16" Height="16" Fill="{StaticResource SortByNameDrawingBrush}" />
</RadioButton>
</hc:ButtonGroup>
<hc:SearchBar x:Name="PART_SearchBar" IsRealTime="True" ShowClearButton="True" Style="{StaticResource SearchBarPlus}" />
</DockPanel>
<hc:PropertyItemsControl Grid.Row="1" x:Name="PART_ItemsControl" Style="{StaticResource PropertyItemsControlBaseStyle}">
<DockPanel LastChildFill="True" Margin="0,0,0,6">
<DockPanel.Visibility>
<MultiBinding Converter="{StaticResource BooleanArr2VisibilityConverter}"
ConverterParameter="UseAny">
<Binding Path="ShowSortButton" RelativeSource="{RelativeSource TemplatedParent}" />
<Binding Path="ShowSearchBar" RelativeSource="{RelativeSource TemplatedParent}" />
</MultiBinding>
</DockPanel.Visibility>
<hc:ButtonGroup Margin="0,0,6,0" Visibility="{Binding ShowSortButton,RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource Boolean2VisibilityConverter}}" Style="{StaticResource ButtonGroupSolid}">
<RadioButton Command="interactivity:ControlCommands.SortByCategory" IsChecked="True">
<Rectangle Width="16" Height="16" Fill="{StaticResource SortByCategoryDrawingBrush}" />
</RadioButton>
<RadioButton Command="interactivity:ControlCommands.SortByName">
<Rectangle Width="16" Height="16" Fill="{StaticResource SortByNameDrawingBrush}" />
</RadioButton>
<RadioButton Command="interactivity:ControlCommands.SortByHierarchyLevel">
<Rectangle Width="16" Height="16" Fill="{StaticResource SortByHierarchyLevelDrawingBrush}" />
</RadioButton>
</hc:ButtonGroup>
<hc:SearchBar x:Name="PART_SearchBar" IsRealTime="True" ShowClearButton="True" Style="{StaticResource SearchBarPlus}"
Visibility="{Binding ShowSearchBar, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource Boolean2VisibilityConverter}}" />
</DockPanel>
<hc:PropertyItemsControl Grid.Row="1" x:Name="PART_ItemsControl" Style="{StaticResource PropertyItemsControlBaseStyle}">
<hc:PropertyItemsControl.GroupStyle>
<GroupStyle ContainerStyle="{StaticResource PropertyGroupItemBaseStyle}" />
</hc:PropertyItemsControl.GroupStyle>
Expand Down Expand Up @@ -13728,4 +13747,4 @@
</Style>
<Style BasedOn="{StaticResource RangeSliderBaseStyle}" TargetType="hc:RangeSlider" />
<Style BasedOn="{StaticResource SliderBaseStyle}" TargetType="Slider" />
</ResourceDictionary>
</ResourceDictionary>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System.ComponentModel;
using System.Windows;
using System.Windows.Media;
using HandyControl.Controls;

namespace HandyControlDemo.Data
{
Expand All @@ -12,12 +13,15 @@ public class PropertyGridDemoModel
[Category("Category2")]
public int Integer { get; set; }

[Category("Category2")]
[Category("Category1"), Priority(3)]
public bool Boolean { get; set; }

[Category("Category1")]
[Category("Category1"), Priority(5), Necessary]
public Gender Enum { get; set; }

[Category("Category1"), Priority(4)]
public DemoDataModel FlattenedType { get; set; }

public HorizontalAlignment HorizontalAlignment { get; set; }

public VerticalAlignment VerticalAlignment { get; set; }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,19 @@
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<hc:PropertyGrid Width="500" SelectedObject="{Binding DemoModel}"/>

<hc:PropertyGrid Width="500"
SelectedObject="{Binding DemoModel}"
FlattenChildProperties="ParentNameAsCategory"
GroupHeaderMargin="0,0,0,5"
SortByPriority="True">
<hc:PropertyGrid.GroupHeaderTemplate>
<DataTemplate>
<TextBlock Height="20" Text="{Binding}" />
</DataTemplate>
</hc:PropertyGrid.GroupHeaderTemplate>
</hc:PropertyGrid>

<StackPanel hc:TitleElement.TitleWidth="168" Grid.Row="1" Margin="20,16,17,10">
<TextBox hc:TitleElement.Title="String" hc:TitleElement.TitlePlacement="Left" Style="{StaticResource TextBoxExtend}" Text="{Binding DemoModel.String,Mode=OneWay}" IsReadOnly="True"/>
<TextBox hc:TitleElement.Title="Enum" hc:TitleElement.TitlePlacement="Left" Style="{StaticResource TextBoxExtend}" Text="{Binding DemoModel.Enum,Mode=OneWay}" IsReadOnly="True" Margin="0,6,0,0"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,12 @@ public PropertyGridDemoCtl()

DemoModel = new PropertyGridDemoModel
{
String = "TestString",
Enum = Gender.Female,
Boolean = true,
Integer = 98,
VerticalAlignment = VerticalAlignment.Stretch
String = "TestString",
Enum = Gender.Female,
Boolean = true,
Integer = 98,
VerticalAlignment = VerticalAlignment.Stretch,
FlattenedType = new DemoDataModel {Index = 0, IsSelected = true, Name = "Flattened", Remark = "Remark", Type = DemoType.Type4}
};
}

Expand Down
13 changes: 10 additions & 3 deletions src/Shared/HandyControl_Shared/Controls/Carousel/Carousel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -268,9 +268,16 @@ public void UpdatePageButtons(int index = -1)
/// </summary>
private void UpdateItemsPosition()
{
if (!CheckNull()) return;
if (!_appliedTemplate) return;
if (Items.Count == 0) return;
if (!CheckNull() || !_appliedTemplate || Items.Count == 0)
{
return;
}

if (PageIndex == -1)
{
PageIndex = 0;
}

if (!IsCenter)
{
ItemsHost.BeginAnimation(MarginProperty,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,66 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Globalization;
using System.Linq;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Data;

namespace HandyControl.Controls
{
public class EnumPropertyEditor : PropertyEditorBase
{
public override FrameworkElement CreateElement(PropertyItem propertyItem) => new System.Windows.Controls.ComboBox
{
IsEnabled = !propertyItem.IsReadOnly,
ItemsSource = Enum.GetValues(propertyItem.PropertyType)
};
public override FrameworkElement CreateElement(PropertyItem propertyItem) =>
new System.Windows.Controls.ComboBox
{
IsEnabled = !propertyItem.IsReadOnly,
ItemsSource = EnumPropertyEditor.GetEnumDescription(propertyItem.PropertyType)
};

public override DependencyProperty GetDependencyProperty() => Selector.SelectedValueProperty;

protected override IValueConverter GetConverter(PropertyItem propertyItem) => new EnumDescriptionConverter(propertyItem.PropertyType);

private static IEnumerable<string> GetEnumDescription(Type enumType)
{
var values = Enum.GetValues(enumType);
var enumDescs = new List<string>(values.Length);

enumDescs.AddRange(from object value in values
select enumType.GetField(value.ToString())
into field
let attributes = field.GetCustomAttributes(typeof(DescriptionAttribute), false)
select (attributes.Length == 0 ? field.Name : ((DescriptionAttribute) attributes[0]).Description));

return enumDescs;
}

private class EnumDescriptionConverter : IValueConverter
{
private readonly List<KeyValuePair<Enum, string>> cache;

public EnumDescriptionConverter(Type enumType)
{
var values = Enum.GetValues(enumType);

cache = new List<KeyValuePair<Enum, string>>(values.Length);

foreach (var value in values)
{
var field = enumType.GetField(value.ToString());
var attributes = field.GetCustomAttributes(typeof(DescriptionAttribute), false);
var fieldValue = (attributes.Length == 0 ? field.Name : ((DescriptionAttribute) attributes[0]).Description);

cache.Add(new KeyValuePair<Enum, string>((Enum) value, fieldValue));
}
}

object IValueConverter.Convert(object value, Type targetType, object parameter, CultureInfo culture) =>
cache.FirstOrDefault(x => x.Key.Equals((Enum) value)).Value;

object IValueConverter.ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) =>
cache.FirstOrDefault(x => x.Value == (string) value).Key;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
using System.Windows;
using System;
using System.Reflection;
using System.Windows;
using System.Windows.Controls.Primitives;
using System.Windows.Data;
using HandyControl.Controls;

namespace HandyControl.Controls
{

public abstract class PropertyEditorBase : DependencyObject
{
public abstract FrameworkElement CreateElement(PropertyItem propertyItem);

public virtual void CreateBinding(PropertyItem propertyItem, DependencyObject element) =>
public virtual void CreateBinding(PropertyItem propertyItem, DependencyObject element)
{
BindingOperations.SetBinding(element, GetDependencyProperty(),
new Binding($"{propertyItem.PropertyName}")
{
Source = propertyItem.Value,
Mode = GetBindingMode(propertyItem),
UpdateSourceTrigger = GetUpdateSourceTrigger(propertyItem),
Converter = GetConverter(propertyItem)
});
new Binding($"{propertyItem.PropertyName}")
{
Source = propertyItem.Value,
Mode = GetBindingMode(propertyItem),
UpdateSourceTrigger = GetUpdateSourceTrigger(propertyItem),
Converter = GetConverter(propertyItem)
});
}

public abstract DependencyProperty GetDependencyProperty();

Expand Down
Loading