From aeb5d2a3b83327921fae8af3476ab44ea6ec86f9 Mon Sep 17 00:00:00 2001
From: NaBian <836904362@qq.com>
Date: Mon, 15 Jun 2020 00:24:18 +0800
Subject: [PATCH 1/6] add partial codes
---
.../HandyControlDemo_Net_40.csproj | 3 +
.../HandyControlDemo_Net_GE45.csproj | 3 +
.../HandyControl_Net_GE45.csproj | 3 +
.../Data/DemoInfo.json | 3 +-
.../HandyControlDemo_Shared.projitems | 7 +
.../Properties/Langs/Lang.Designer.cs | 13 +-
.../Properties/Langs/Lang.en.resx | 3 +
.../Properties/Langs/Lang.fa.resx | 3 +
.../Properties/Langs/Lang.fr.resx | 3 +
.../Properties/Langs/Lang.ko-KR.resx | 3 +
.../Properties/Langs/Lang.resx | 3 +
.../Properties/Langs/Lang.ru.resx | 3 +
.../Properties/Langs/Lang.tr.resx | 3 +
.../Properties/Langs/LangProvider.cs | 13 +-
.../PropertyGridEditorPart_16x.png | Bin 0 -> 173 bytes
.../Controls/PropertyGridDemoCtl.xaml | 7 +
.../Controls/PropertyGridDemoCtl.xaml.cs | 10 ++
.../Editors/BooleanPropertyEditor.cs | 23 +++
.../Editors/DateTimePropertyEditor.cs | 19 +++
.../Editors/IntegerPropertyEditor.cs | 31 ++++
.../Editors/PropertyEditorBase.cs | 18 ++
.../Editors/StringPropertyEditor.cs | 19 +++
.../Controls/PropertyGrid/PropertyGrid.cs | 103 +++++++++++
.../Controls/PropertyGrid/PropertyItem.cs | 141 +++++++++++++++
.../PropertyGrid/PropertyItemsControl.cs | 9 +
.../Controls/PropertyGrid/PropertyResolver.cs | 160 ++++++++++++++++++
.../HandyControl_Shared.projitems | 14 ++
.../Properties/Langs/Lang.Designer.cs | 13 +-
.../Properties/Langs/Lang.en.resx | 3 +
.../Properties/Langs/Lang.fa.resx | 3 +
.../Properties/Langs/Lang.fr.resx | 3 +
.../Properties/Langs/Lang.ko-KR.resx | 3 +
.../Properties/Langs/Lang.resx | 3 +
.../Properties/Langs/Lang.ru.resx | 3 +
.../Properties/Langs/Lang.tr.resx | 3 +
.../Styles/Base/PropertyGridBaseStyle.xaml | 144 ++++++++++++++++
.../Extension/CustomAttributeExtension.cs | 12 ++
37 files changed, 806 insertions(+), 4 deletions(-)
create mode 100644 src/Shared/HandyControlDemo_Shared/Resources/Img/LeftMainContent/PropertyGridEditorPart_16x.png
create mode 100644 src/Shared/HandyControlDemo_Shared/UserControl/Controls/PropertyGridDemoCtl.xaml
create mode 100644 src/Shared/HandyControlDemo_Shared/UserControl/Controls/PropertyGridDemoCtl.xaml.cs
create mode 100644 src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/BooleanPropertyEditor.cs
create mode 100644 src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/DateTimePropertyEditor.cs
create mode 100644 src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/IntegerPropertyEditor.cs
create mode 100644 src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/PropertyEditorBase.cs
create mode 100644 src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/StringPropertyEditor.cs
create mode 100644 src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyGrid.cs
create mode 100644 src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyItem.cs
create mode 100644 src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyItemsControl.cs
create mode 100644 src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyResolver.cs
create mode 100644 src/Shared/HandyControl_Shared/Themes/Styles/Base/PropertyGridBaseStyle.xaml
create mode 100644 src/Shared/HandyControl_Shared/Tools/Extension/CustomAttributeExtension.cs
diff --git a/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj b/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj
index 81d86893..c3b5331e 100644
--- a/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj
+++ b/src/Net_40/HandyControlDemo_Net_40/HandyControlDemo_Net_40.csproj
@@ -313,6 +313,9 @@
Resources\Img\LeftMainContent\RadioButton_16x.png
+
+ Resources\Img\LeftMainContent\PropertyGridEditorPart_16x.png
+
Resources\Img\LeftMainContent\RepeatButton_16x.png
diff --git a/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj b/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj
index a4a7980a..bdb2f1da 100644
--- a/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj
+++ b/src/Net_GE45/HandyControlDemo_Net_GE45/HandyControlDemo_Net_GE45.csproj
@@ -313,6 +313,9 @@
Resources\Img\LeftMainContent\RadioButton_16x.png
+
+ Resources\Img\LeftMainContent\PropertyGridEditorPart_16x.png
+
Resources\Img\LeftMainContent\RepeatButton_16x.png
diff --git a/src/Net_GE45/HandyControl_Net_GE45/HandyControl_Net_GE45.csproj b/src/Net_GE45/HandyControl_Net_GE45/HandyControl_Net_GE45.csproj
index 936ec214..3d75fe2c 100644
--- a/src/Net_GE45/HandyControl_Net_GE45/HandyControl_Net_GE45.csproj
+++ b/src/Net_GE45/HandyControl_Net_GE45/HandyControl_Net_GE45.csproj
@@ -134,4 +134,7 @@
Resources\Images\GlowWindow\topright.png
+
+
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Data/DemoInfo.json b/src/Shared/HandyControlDemo_Shared/Data/DemoInfo.json
index e69dda21..288b158d 100644
--- a/src/Shared/HandyControlDemo_Shared/Data/DemoInfo.json
+++ b/src/Shared/HandyControlDemo_Shared/Data/DemoInfo.json
@@ -39,6 +39,7 @@
"title": "Controls",
"selectedIndex": 0,
"demoItemList": [
+ [ "PropertyGrid", "PropertyGridDemoCtl", "PropertyGridEditorPart_16x", "1" ],
[ "FloatingBlock", "FloatingBlockDemoCtl", "thumbs_up", "" ],
[ "ImageBlock", "ImageBlockDemoCtl", "ImageStack_16x", "" ],
[ "Magnifier", "MagnifierDemoCtl", "Search_16x", "" ],
@@ -55,7 +56,7 @@
[ "TextBox", "TextBoxDemoCtl", "TextBox_16x", "" ],
[ "ComboBox", "ComboBoxDemoCtl", "ComboBox_16x", "" ],
[ "PasswordBox", "PasswordBoxDemoCtl", "PasswordBox_16x", "" ],
- [ "PinBox", "PinBoxDemoCtl", "Ellipsis_16x", "1" ],
+ [ "PinBox", "PinBoxDemoCtl", "Ellipsis_16x", "" ],
[ "DatePicker", "DatePickerDemoCtl", "DatePicker_16x", "" ],
[ "Clock", "ClockDemoCtl", "Time_color_16x", "" ],
[ "TimePicker", "TimePickerDemoCtl", "TimePicker_16x", "" ],
diff --git a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems
index b28427b0..6dc16fbe 100644
--- a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems
+++ b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems
@@ -84,6 +84,9 @@
PinBoxDemoCtl.xaml
+
+ PropertyGridDemoCtl.xaml
+
RangeSliderDemoCtl.xaml
@@ -548,6 +551,10 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.Designer.cs b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.Designer.cs
index eb2498b4..d6b6456b 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.Designer.cs
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.Designer.cs
@@ -1337,7 +1337,18 @@ namespace HandyControlDemo.Properties.Langs {
return ResourceManager.GetString("Project", resourceCulture);
}
}
-
+
+ ///
+ /// 查找类似 属性编辑器 的本地化字符串。
+ ///
+ public static string PropertyGrid
+ {
+ get
+ {
+ return ResourceManager.GetString("PropertyGrid", resourceCulture);
+ }
+ }
+
///
/// 查找类似 按住说话 的本地化字符串。
///
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx
index 324db1ca..0f8f8540 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.en.resx
@@ -750,4 +750,7 @@
Looks up a localized string similar to "{0}".
+
+ PropertyGrid
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fa.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fa.resx
index 75ebfd5d..f176e3e2 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fa.resx
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fa.resx
@@ -750,4 +750,7 @@
Looks up a localized string similar to "{0}".
+
+ PropertyGrid
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fr.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fr.resx
index 8e17aff4..1f15b560 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fr.resx
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.fr.resx
@@ -750,4 +750,7 @@
Looks up a localized string similar to "{0}".
+
+ PropertyGrid
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ko-KR.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ko-KR.resx
index f3f49253..fe9f13ee 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ko-KR.resx
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ko-KR.resx
@@ -750,4 +750,7 @@
Looks up a localized string similar to "{0}".
+
+ PropertyGrid
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.resx
index 455582c2..e876c1bc 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.resx
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.resx
@@ -750,4 +750,7 @@
查找类似 {0} 的本地化字符串。
+
+ 属性编辑器
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ru.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ru.resx
index 324db1ca..0f8f8540 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ru.resx
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.ru.resx
@@ -750,4 +750,7 @@
Looks up a localized string similar to "{0}".
+
+ PropertyGrid
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.tr.resx b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.tr.resx
index f7354d30..f0fb5b5c 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.tr.resx
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/Lang.tr.resx
@@ -750,4 +750,7 @@
Looks up a localized string similar to "{0}".
+
+ PropertyGrid
+
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/Properties/Langs/LangProvider.cs b/src/Shared/HandyControlDemo_Shared/Properties/Langs/LangProvider.cs
index 5dd7cb48..e031d4b3 100644
--- a/src/Shared/HandyControlDemo_Shared/Properties/Langs/LangProvider.cs
+++ b/src/Shared/HandyControlDemo_Shared/Properties/Langs/LangProvider.cs
@@ -179,7 +179,8 @@ namespace HandyControlDemo.Properties.Langs
OnPropertyChanged(nameof(ProgressBar));
OnPropertyChanged(nameof(ProgressButton));
OnPropertyChanged(nameof(Project));
- OnPropertyChanged(nameof(PushToTalk));
+ OnPropertyChanged(nameof(PropertyGrid));
+ OnPropertyChanged(nameof(PushToTalk));
OnPropertyChanged(nameof(QQGroup));
OnPropertyChanged(nameof(RadioButton));
OnPropertyChanged(nameof(RangeSlider));
@@ -960,6 +961,11 @@ namespace HandyControlDemo.Properties.Langs
///
public string Project => Lang.Project;
+ ///
+ /// 查找类似 属性编辑器 的本地化字符串。
+ ///
+ public string PropertyGrid => Lang.PropertyGrid;
+
///
/// 查找类似 按住说话 的本地化字符串。
///
@@ -2024,6 +2030,11 @@ namespace HandyControlDemo.Properties.Langs
///
public static string Project = nameof(Project);
+ ///
+ /// 查找类似 属性编辑器 的本地化字符串。
+ ///
+ public static string PropertyGrid = nameof(PropertyGrid);
+
///
/// 查找类似 按住说话 的本地化字符串。
///
diff --git a/src/Shared/HandyControlDemo_Shared/Resources/Img/LeftMainContent/PropertyGridEditorPart_16x.png b/src/Shared/HandyControlDemo_Shared/Resources/Img/LeftMainContent/PropertyGridEditorPart_16x.png
new file mode 100644
index 0000000000000000000000000000000000000000..09bdd02d1c52b921a785e3eba924cc573cd0ec0e
GIT binary patch
literal 173
zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61|;P_|4#%`oCO|{#S9F5he4R}c>anMpkTbG
zi(^Pd+}_ECd<=>lEVZ}){nyXhyf*xzK#Jl{>&d(eXZ9>mwo>so4QF5w<&7x5AH-I{
z%=|w;;qPy@wNn{67_Y6ECADOiig3fe{F@4Mwn(z9-<^{
S?zjwS6@#a%pUXO@geCxpvpG!w
literal 0
HcmV?d00001
diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/PropertyGridDemoCtl.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/PropertyGridDemoCtl.xaml
new file mode 100644
index 00000000..37108e68
--- /dev/null
+++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/PropertyGridDemoCtl.xaml
@@ -0,0 +1,7 @@
+
+
+
diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/PropertyGridDemoCtl.xaml.cs b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/PropertyGridDemoCtl.xaml.cs
new file mode 100644
index 00000000..adb77878
--- /dev/null
+++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/PropertyGridDemoCtl.xaml.cs
@@ -0,0 +1,10 @@
+namespace HandyControlDemo.UserControl
+{
+ public partial class PropertyGridDemoCtl
+ {
+ public PropertyGridDemoCtl()
+ {
+ InitializeComponent();
+ }
+ }
+}
diff --git a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/BooleanPropertyEditor.cs b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/BooleanPropertyEditor.cs
new file mode 100644
index 00000000..4601d51c
--- /dev/null
+++ b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/BooleanPropertyEditor.cs
@@ -0,0 +1,23 @@
+using System.Windows;
+using System.Windows.Controls.Primitives;
+using HandyControl.Tools;
+
+namespace HandyControl.Controls
+{
+ public class BooleanPropertyEditor : PropertyEditorBase
+ {
+ public override FrameworkElement CreateElement(PropertyItem propertyItem)
+ {
+ var button = new ToggleButton
+ {
+ Style = ResourceHelper.GetResource
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/Shared/HandyControl_Shared/Tools/Extension/CustomAttributeExtension.cs b/src/Shared/HandyControl_Shared/Tools/Extension/CustomAttributeExtension.cs
new file mode 100644
index 00000000..f50c4d9e
--- /dev/null
+++ b/src/Shared/HandyControl_Shared/Tools/Extension/CustomAttributeExtension.cs
@@ -0,0 +1,12 @@
+using System;
+using System.Reflection;
+
+namespace HandyControl.Tools.Extension
+{
+ internal static class CustomAttributeExtension
+ {
+ public static Attribute GetCustomAttribute(this MemberInfo element, Type attributeType) => Attribute.GetCustomAttribute(element, attributeType);
+
+ public static T GetCustomAttribute(this MemberInfo element) where T : Attribute => (T)GetCustomAttribute(element, typeof(T));
+ }
+}
\ No newline at end of file
From 0a9d95fafd81980e8f2f6d001748f44c8dc2bf13 Mon Sep 17 00:00:00 2001
From: NaBian <836904362@qq.com>
Date: Mon, 15 Jun 2020 00:27:04 +0800
Subject: [PATCH 2/6] Update Directory.Build.Props
---
src/Directory.Build.Props | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/src/Directory.Build.Props b/src/Directory.Build.Props
index 7afc4ff0..f9bf59c1 100644
--- a/src/Directory.Build.Props
+++ b/src/Directory.Build.Props
@@ -1,9 +1,9 @@
true
- 2.5.0.1
- 2.5.0.1
- 2.5.0.1
+ 3.0.0.0
+ 3.0.0.0
+ 3.0.0.0
8.0
Copyright © HandyOrg 2018-2020
HandyOrg
From f7a39f3d325d4e2d1a316f905326026cd4953e53 Mon Sep 17 00:00:00 2001
From: NaBian <836904362@qq.com>
Date: Mon, 15 Jun 2020 22:47:04 +0800
Subject: [PATCH 3/6] add PropertyGrid Demo
---
.../Controls/PropertyGridDemoCtl.xaml | 20 ++-
.../Editors/DatePropertyEditor.cs | 19 +++
.../Editors/IntegerPropertyEditor.cs | 4 +-
.../Editors/NumberPropertyEditor.cs | 36 +++++
.../Editors/PlainTextPropertyEditor.cs | 19 +++
.../Editors/PropertyEditorBase.cs | 8 +-
.../Editors/StringPropertyEditor.cs | 2 +-
...pertyEditor.cs => SwitchPropertyEditor.cs} | 2 +-
.../Editors/TimePropertyEditor.cs | 19 +++
.../Controls/PropertyGrid/PropertyGrid.cs | 141 ++++++++++++++----
.../Controls/PropertyGrid/PropertyItem.cs | 9 --
.../Controls/PropertyGrid/PropertyResolver.cs | 33 ++--
.../HandyControl_Shared.projitems | 12 +-
.../Interactivity/Commands/ControlCommands.cs | 10 ++
.../Styles/Base/PropertyGridBaseStyle.xaml | 47 +++---
.../Themes/Styles/Base/ToolTipBaseStyle.xaml | 9 +-
.../Themes/Styles/PropertyGrid.xaml | 11 ++
.../Themes/Styles/Style.xaml | 1 +
18 files changed, 320 insertions(+), 82 deletions(-)
create mode 100644 src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/DatePropertyEditor.cs
create mode 100644 src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/NumberPropertyEditor.cs
create mode 100644 src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/PlainTextPropertyEditor.cs
rename src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/{BooleanPropertyEditor.cs => SwitchPropertyEditor.cs} (91%)
create mode 100644 src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/TimePropertyEditor.cs
create mode 100644 src/Shared/HandyControl_Shared/Themes/Styles/PropertyGrid.xaml
diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/PropertyGridDemoCtl.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/PropertyGridDemoCtl.xaml
index 37108e68..eff6b153 100644
--- a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/PropertyGridDemoCtl.xaml
+++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/PropertyGridDemoCtl.xaml
@@ -1,7 +1,23 @@
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/DatePropertyEditor.cs b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/DatePropertyEditor.cs
new file mode 100644
index 00000000..6ca651c2
--- /dev/null
+++ b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/DatePropertyEditor.cs
@@ -0,0 +1,19 @@
+using System.Windows;
+
+namespace HandyControl.Controls
+{
+ public class DatePropertyEditor : PropertyEditorBase
+ {
+ public override FrameworkElement CreateElement(PropertyItem propertyItem)
+ {
+ var picker = new DateTimePicker
+ {
+ IsEnabled = !propertyItem.IsReadOnly
+ };
+
+ picker.SetBinding(System.Windows.Controls.DatePicker.SelectedDateProperty, CreateBinding(propertyItem));
+
+ return picker;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/IntegerPropertyEditor.cs b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/IntegerPropertyEditor.cs
index 849f62e1..bd48007b 100644
--- a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/IntegerPropertyEditor.cs
+++ b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/IntegerPropertyEditor.cs
@@ -2,9 +2,9 @@
namespace HandyControl.Controls
{
- public class IntegerPropertyEditor : PropertyEditorBase
+ public class NumberPropertyEditor : PropertyEditorBase
{
- public IntegerPropertyEditor(double minimum, double maximum)
+ public NumberPropertyEditor(double minimum, double maximum)
{
Minimum = minimum;
Maximum = maximum;
diff --git a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/NumberPropertyEditor.cs b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/NumberPropertyEditor.cs
new file mode 100644
index 00000000..305bcd9f
--- /dev/null
+++ b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/NumberPropertyEditor.cs
@@ -0,0 +1,36 @@
+using System.Windows;
+
+namespace HandyControl.Controls
+{
+ public class NumberPropertyEditor : PropertyEditorBase
+ {
+ public NumberPropertyEditor()
+ {
+
+ }
+
+ public NumberPropertyEditor(double minimum, double maximum)
+ {
+ Minimum = minimum;
+ Maximum = maximum;
+ }
+
+ public double Minimum { get; set; }
+
+ public double Maximum { get; set; }
+
+ public override FrameworkElement CreateElement(PropertyItem propertyItem)
+ {
+ var numericUpDown = new NumericUpDown
+ {
+ IsReadOnly = propertyItem.IsReadOnly,
+ Minimum = Minimum,
+ Maximum = Maximum
+ };
+
+ numericUpDown.SetBinding(NumericUpDown.ValueProperty, CreateBinding(propertyItem));
+
+ return numericUpDown;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/PlainTextPropertyEditor.cs b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/PlainTextPropertyEditor.cs
new file mode 100644
index 00000000..77663d9b
--- /dev/null
+++ b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/PlainTextPropertyEditor.cs
@@ -0,0 +1,19 @@
+using System.Windows;
+
+namespace HandyControl.Controls
+{
+ public class PlainTextPropertyEditor : PropertyEditorBase
+ {
+ public override FrameworkElement CreateElement(PropertyItem propertyItem)
+ {
+ var textbox = new System.Windows.Controls.TextBox
+ {
+ IsReadOnly = propertyItem.IsReadOnly
+ };
+
+ textbox.SetBinding(System.Windows.Controls.TextBox.TextProperty, CreateBinding(propertyItem));
+
+ return textbox;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/PropertyEditorBase.cs b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/PropertyEditorBase.cs
index 927779a0..bda2df14 100644
--- a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/PropertyEditorBase.cs
+++ b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/PropertyEditorBase.cs
@@ -11,8 +11,12 @@ namespace HandyControl.Controls
new Binding(propertyItem.PropertyName)
{
Source = propertyItem.Value,
- Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay,
- UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
+ Mode = GetBindingMode(),
+ UpdateSourceTrigger = GetUpdateSourceTrigger()
};
+
+ public virtual BindingMode GetBindingMode() => BindingMode.OneWay;
+
+ public virtual UpdateSourceTrigger GetUpdateSourceTrigger() => UpdateSourceTrigger.Default;
}
}
\ No newline at end of file
diff --git a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/StringPropertyEditor.cs b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/StringPropertyEditor.cs
index cdd5ef28..77663d9b 100644
--- a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/StringPropertyEditor.cs
+++ b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/StringPropertyEditor.cs
@@ -2,7 +2,7 @@
namespace HandyControl.Controls
{
- public class StringPropertyEditor : PropertyEditorBase
+ public class PlainTextPropertyEditor : PropertyEditorBase
{
public override FrameworkElement CreateElement(PropertyItem propertyItem)
{
diff --git a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/BooleanPropertyEditor.cs b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/SwitchPropertyEditor.cs
similarity index 91%
rename from src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/BooleanPropertyEditor.cs
rename to src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/SwitchPropertyEditor.cs
index 4601d51c..706646be 100644
--- a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/BooleanPropertyEditor.cs
+++ b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/SwitchPropertyEditor.cs
@@ -4,7 +4,7 @@ using HandyControl.Tools;
namespace HandyControl.Controls
{
- public class BooleanPropertyEditor : PropertyEditorBase
+ public class SwitchPropertyEditor : PropertyEditorBase
{
public override FrameworkElement CreateElement(PropertyItem propertyItem)
{
diff --git a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/TimePropertyEditor.cs b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/TimePropertyEditor.cs
new file mode 100644
index 00000000..d39ca9c4
--- /dev/null
+++ b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/TimePropertyEditor.cs
@@ -0,0 +1,19 @@
+using System.Windows;
+
+namespace HandyControl.Controls
+{
+ public class TimePropertyEditor : PropertyEditorBase
+ {
+ public override FrameworkElement CreateElement(PropertyItem propertyItem)
+ {
+ var picker = new DateTimePicker
+ {
+ IsEnabled = !propertyItem.IsReadOnly
+ };
+
+ picker.SetBinding(TimePicker.SelectedTimeProperty, CreateBinding(propertyItem));
+
+ return picker;
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyGrid.cs b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyGrid.cs
index e1b26beb..df67f1a5 100644
--- a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyGrid.cs
+++ b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyGrid.cs
@@ -1,20 +1,39 @@
-using System.Collections.Generic;
+using System;
+using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
+using System.Windows.Input;
+using HandyControl.Data;
+using HandyControl.Interactivity;
using HandyControl.Tools.Extension;
namespace HandyControl.Controls
{
[TemplatePart(Name = ElementItemsControl, Type = typeof(ItemsControl))]
+ [TemplatePart(Name = ElementSearchBar, Type = typeof(SearchBar))]
public class PropertyGrid : Control
{
private const string ElementItemsControl = "PART_ItemsControl";
+ private const string ElementSearchBar = "PART_SearchBar";
+
private ItemsControl _itemsControl;
+ private ICollectionView _dataView;
+
+ private SearchBar _searchBar;
+
+ private string _searchKey;
+
+ public PropertyGrid()
+ {
+ CommandBindings.Add(new CommandBinding(ControlCommands.SortByCategory, SortByCategory));
+ CommandBindings.Add(new CommandBinding(ControlCommands.SortByName, SortByName));
+ }
+
public virtual PropertyResolver PropertyResolver { get; } = new PropertyResolver();
public static readonly RoutedEvent SelectedObjectChangedEvent =
@@ -57,11 +76,41 @@ namespace HandyControl.Controls
set => SetValue(DescriptionProperty, value);
}
+ public static readonly DependencyProperty MaxTitleWidthProperty = DependencyProperty.Register(
+ "MaxTitleWidth", typeof(double), typeof(PropertyGrid), new PropertyMetadata(default(double)));
+
+ public double MaxTitleWidth
+ {
+ get => (double) GetValue(MaxTitleWidthProperty);
+ set => SetValue(MaxTitleWidthProperty, value);
+ }
+
+ public static readonly DependencyProperty MinTitleWidthProperty = DependencyProperty.Register(
+ "MinTitleWidth", typeof(double), typeof(PropertyGrid), new PropertyMetadata(default(double)));
+
+ public double MinTitleWidth
+ {
+ get => (double) GetValue(MinTitleWidthProperty);
+ set => SetValue(MinTitleWidthProperty, value);
+ }
+
public override void OnApplyTemplate()
{
+ if (_searchBar != null)
+ {
+ _searchBar.SearchStarted -= SearchBar_SearchStarted;
+ }
+
base.OnApplyTemplate();
_itemsControl = GetTemplateChild(ElementItemsControl) as ItemsControl;
+ _searchBar = GetTemplateChild(ElementSearchBar) as SearchBar;
+
+ if (_searchBar != null)
+ {
+ _searchBar.SearchStarted += SearchBar_SearchStarted;
+ }
+
UpdateItems(SelectedObject);
}
@@ -69,35 +118,73 @@ namespace HandyControl.Controls
{
if (obj == null || _itemsControl == null) return;
- var type = obj.GetType();
- var propertyInfos = type.GetProperties();
- var itemList = propertyInfos.Select(CreatePropertyItem).Do(item => item.InitElement()).ToList();
- _itemsControl.ItemsSource = itemList;
+ _dataView = CollectionViewSource.GetDefaultView(obj.GetType().GetProperties()
+ .Where(item => PropertyResolver.ResolveBrowsable(item)).Select(CreatePropertyItem)
+ .Do(item => item.InitElement()));
- var categorySet = new HashSet();
- foreach (var propertyItem in itemList)
- {
- categorySet.Add(propertyItem.Category);
- }
-
- var view = CollectionViewSource.GetDefaultView(itemList);
- view.GroupDescriptions.Add(new PropertyGroupDescription("Category"));
+ SortByCategory(null, null);
+ _itemsControl.ItemsSource = _dataView;
}
- protected virtual PropertyItem CreatePropertyItem(PropertyInfo propertyInfo) =>
- new PropertyItem
+ private void SortByCategory(object sender, ExecutedRoutedEventArgs e)
+ {
+ using (_dataView.DeferRefresh())
{
- Category = PropertyResolver.ResolveCategory(propertyInfo),
- DisplayName = PropertyResolver.ResolveDisplayName(propertyInfo),
- Description = PropertyResolver.ResolveDescription(propertyInfo),
- Browsable = PropertyResolver.ResolveBrowsable(propertyInfo),
- IsReadOnly = PropertyResolver.ResolveIsReadOnly(propertyInfo),
- DefaultValue = PropertyResolver.ResolveDefaultValue(propertyInfo),
- Editor = PropertyResolver.ResolveEditor(propertyInfo),
- Converter = PropertyResolver.ResolveConverter(propertyInfo),
- Value = SelectedObject,
- PropertyName = propertyInfo.Name,
- PropertyTypeName = propertyInfo.PropertyType.FullName
- };
+ _dataView.GroupDescriptions.Clear();
+ _dataView.SortDescriptions.Clear();
+ _dataView.SortDescriptions.Add(new SortDescription(PropertyItem.CategoryProperty.Name, ListSortDirection.Ascending));
+ _dataView.SortDescriptions.Add(new SortDescription(PropertyItem.PropertyNameProperty.Name, ListSortDirection.Ascending));
+ _dataView.GroupDescriptions.Add(new PropertyGroupDescription(PropertyItem.CategoryProperty.Name));
+ }
+ }
+
+ private void SortByName(object sender, ExecutedRoutedEventArgs e)
+ {
+ using (_dataView.DeferRefresh())
+ {
+ _dataView.GroupDescriptions.Clear();
+ _dataView.SortDescriptions.Clear();
+ _dataView.SortDescriptions.Add(new SortDescription(PropertyItem.PropertyNameProperty.Name, ListSortDirection.Ascending));
+ }
+ }
+
+ private void SearchBar_SearchStarted(object sender, FunctionEventArgs e)
+ {
+ _searchKey = e.Info;
+ if (string.IsNullOrEmpty(_searchKey))
+ {
+ foreach (UIElement item in _dataView)
+ {
+ item.Show();
+ }
+ }
+ else
+ {
+ foreach (PropertyItem item in _dataView)
+ {
+ item.Show(item.PropertyName.ToLower().Contains(_searchKey) || item.DisplayName.ToLower().Contains(_searchKey));
+ }
+ }
+ }
+
+ protected virtual PropertyItem CreatePropertyItem(PropertyInfo propertyInfo) => new PropertyItem
+ {
+ Category = PropertyResolver.ResolveCategory(propertyInfo),
+ DisplayName = PropertyResolver.ResolveDisplayName(propertyInfo),
+ Description = PropertyResolver.ResolveDescription(propertyInfo),
+ IsReadOnly = PropertyResolver.ResolveIsReadOnly(propertyInfo),
+ DefaultValue = PropertyResolver.ResolveDefaultValue(propertyInfo),
+ Editor = PropertyResolver.ResolveEditor(propertyInfo),
+ Converter = PropertyResolver.ResolveConverter(propertyInfo),
+ Value = SelectedObject,
+ PropertyName = propertyInfo.Name,
+ PropertyTypeName = propertyInfo.PropertyType.FullName
+ };
+
+ protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
+ {
+ base.OnRenderSizeChanged(sizeInfo);
+ TitleElement.SetTitleWidth(this, new GridLength(Math.Max(MinTitleWidth, Math.Min(MaxTitleWidth, ActualWidth / 3))));
+ }
}
}
\ No newline at end of file
diff --git a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyItem.cs b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyItem.cs
index 6b4f8c71..77d2075d 100644
--- a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyItem.cs
+++ b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyItem.cs
@@ -51,15 +51,6 @@ namespace HandyControl.Controls
set => SetValue(DescriptionProperty, value);
}
- public static readonly DependencyProperty BrowsableProperty = DependencyProperty.Register(
- "Browsable", typeof(bool), typeof(PropertyItem), new PropertyMetadata(default(bool)));
-
- public bool Browsable
- {
- get => (bool)GetValue(BrowsableProperty);
- set => SetValue(BrowsableProperty, value);
- }
-
public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register(
"IsReadOnly", typeof(bool), typeof(PropertyItem), new PropertyMetadata(default(bool)));
diff --git a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyResolver.cs b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyResolver.cs
index 8fc8c230..baceed87 100644
--- a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyResolver.cs
+++ b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyResolver.cs
@@ -25,7 +25,8 @@ namespace HandyControl.Controls
[typeof(ulong)] = EditorTypeCode.UInt64Number,
[typeof(float)] = EditorTypeCode.SingleNumber,
[typeof(double)] = EditorTypeCode.DoubleNumber,
- [typeof(bool)] = EditorTypeCode.Switch
+ [typeof(bool)] = EditorTypeCode.Switch,
+ [typeof(DateTime)] = EditorTypeCode.DateTime
};
public string ResolveCategory(PropertyInfo propertyInfo)
@@ -121,24 +122,24 @@ namespace HandyControl.Controls
TypeCodeDic.TryGetValue(type, out var editorType)
? (PropertyEditorBase) (editorType switch
{
- EditorTypeCode.PlainText => new StringPropertyEditor(),
- EditorTypeCode.SByteNumber => new IntegerPropertyEditor(sbyte.MinValue, sbyte.MaxValue),
- EditorTypeCode.ByteNumber => new IntegerPropertyEditor(byte.MinValue, byte.MaxValue),
- EditorTypeCode.Int16Number => new IntegerPropertyEditor(short.MinValue, short.MaxValue),
- EditorTypeCode.UInt16Number => new IntegerPropertyEditor(ushort.MinValue, ushort.MaxValue),
- EditorTypeCode.Int32Number => new IntegerPropertyEditor(int.MinValue, int.MaxValue),
- EditorTypeCode.UInt32Number => new IntegerPropertyEditor(uint.MinValue, uint.MaxValue),
- EditorTypeCode.Int64Number => new IntegerPropertyEditor(long.MinValue, long.MaxValue),
- EditorTypeCode.UInt64Number => new IntegerPropertyEditor(ulong.MinValue, ulong.MaxValue),
- EditorTypeCode.SingleNumber => new IntegerPropertyEditor(float.MinValue, float.MaxValue),
- EditorTypeCode.DoubleNumber => new IntegerPropertyEditor(double.MinValue, double.MaxValue),
- EditorTypeCode.Switch => new BooleanPropertyEditor(),
+ 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(),
- _ => new StringPropertyEditor()
+ _ => new PlainTextPropertyEditor()
})
- : new StringPropertyEditor();
+ : new PlainTextPropertyEditor();
- public virtual PropertyEditorBase CreateEditor(Type type) => new StringPropertyEditor();
+ public virtual PropertyEditorBase CreateEditor(Type type) => new PlainTextPropertyEditor();
private enum EditorTypeCode
{
diff --git a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems
index 4e9427f6..d4698ad5 100644
--- a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems
+++ b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems
@@ -40,11 +40,13 @@
-
+
+
+
-
-
+
+
@@ -429,6 +431,10 @@
Designer
MSBuild:Compile
+
+ Designer
+ MSBuild:Compile
+
Designer
MSBuild:Compile
diff --git a/src/Shared/HandyControl_Shared/Interactivity/Commands/ControlCommands.cs b/src/Shared/HandyControl_Shared/Interactivity/Commands/ControlCommands.cs
index 6e31c2b2..fdcf231b 100644
--- a/src/Shared/HandyControl_Shared/Interactivity/Commands/ControlCommands.cs
+++ b/src/Shared/HandyControl_Shared/Interactivity/Commands/ControlCommands.cs
@@ -171,5 +171,15 @@ namespace HandyControl.Interactivity
/// 开始截图
///
public static StartScreenshotCommand StartScreenshot { get; } = new StartScreenshotCommand();
+
+ ///
+ /// 按照类别排序
+ ///
+ public static RoutedCommand SortByCategory { get; } = new RoutedCommand(nameof(SortByCategory), typeof(ControlCommands));
+
+ ///
+ /// 按照名称排序
+ ///
+ public static RoutedCommand SortByName { get; } = new RoutedCommand(nameof(SortByName), typeof(ControlCommands));
}
}
\ No newline at end of file
diff --git a/src/Shared/HandyControl_Shared/Themes/Styles/Base/PropertyGridBaseStyle.xaml b/src/Shared/HandyControl_Shared/Themes/Styles/Base/PropertyGridBaseStyle.xaml
index b0b8b236..bbe21694 100644
--- a/src/Shared/HandyControl_Shared/Themes/Styles/Base/PropertyGridBaseStyle.xaml
+++ b/src/Shared/HandyControl_Shared/Themes/Styles/Base/PropertyGridBaseStyle.xaml
@@ -2,10 +2,14 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:o="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
xmlns:hc="clr-namespace:HandyControl.Controls"
- xmlns:themes="clr-namespace:HandyControl.Themes">
+ xmlns:themes="clr-namespace:HandyControl.Themes"
+ xmlns:interactivity="clr-namespace:HandyControl.Interactivity">
+
+
+
@@ -20,7 +24,7 @@
-
+
@@ -34,10 +38,11 @@
+
+
+
+
+
+