diff --git a/src/Shared/HandyControlDemo_Shared/Data/DemoInfo.json b/src/Shared/HandyControlDemo_Shared/Data/DemoInfo.json
index 288b158d..7ee1eeb7 100644
--- a/src/Shared/HandyControlDemo_Shared/Data/DemoInfo.json
+++ b/src/Shared/HandyControlDemo_Shared/Data/DemoInfo.json
@@ -39,8 +39,8 @@
"title": "Controls",
"selectedIndex": 0,
"demoItemList": [
- [ "PropertyGrid", "PropertyGridDemoCtl", "PropertyGridEditorPart_16x", "1" ],
[ "FloatingBlock", "FloatingBlockDemoCtl", "thumbs_up", "" ],
+ [ "PropertyGrid", "PropertyGridDemoCtl", "PropertyGridEditorPart_16x", "1" ],
[ "ImageBlock", "ImageBlockDemoCtl", "ImageStack_16x", "" ],
[ "Magnifier", "MagnifierDemoCtl", "Search_16x", "" ],
[ "Gravatar", "GravatarDemoCtl", "User_16x", "" ],
diff --git a/src/Shared/HandyControlDemo_Shared/Data/Model/PropertyGridDemoModel.cs b/src/Shared/HandyControlDemo_Shared/Data/Model/PropertyGridDemoModel.cs
new file mode 100644
index 00000000..f68bcb6e
--- /dev/null
+++ b/src/Shared/HandyControlDemo_Shared/Data/Model/PropertyGridDemoModel.cs
@@ -0,0 +1,25 @@
+using System.ComponentModel;
+
+namespace HandyControlDemo.Data
+{
+ public class PropertyGridDemoModel
+ {
+ [Category("Info")]
+ public string Name { get; set; }
+
+ [Category("Achievement")]
+ public int Score { get; set; }
+
+ [Category("Achievement")]
+ public bool IsPassed { get; set; }
+
+ [Category("Info")]
+ public Gender Gender { get; set; }
+ }
+
+ public enum Gender
+ {
+ Male,
+ Female
+ }
+}
\ No newline at end of file
diff --git a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems
index 6dc16fbe..27573381 100644
--- a/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems
+++ b/src/Shared/HandyControlDemo_Shared/HandyControlDemo_Shared.projitems
@@ -19,6 +19,7 @@
+
diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/PropertyGridDemoCtl.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/PropertyGridDemoCtl.xaml
index fe356a58..72a917de 100644
--- a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/PropertyGridDemoCtl.xaml
+++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/PropertyGridDemoCtl.xaml
@@ -2,20 +2,21 @@
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol"
- Background="{DynamicResource RegionBrush}">
+ Background="{DynamicResource RegionBrush}"
+ DataContext="{Binding RelativeSource={RelativeSource Self}}">
-
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/PropertyGridDemoCtl.xaml.cs b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/PropertyGridDemoCtl.xaml.cs
index adb77878..4cf3e692 100644
--- a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/PropertyGridDemoCtl.xaml.cs
+++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/PropertyGridDemoCtl.xaml.cs
@@ -1,10 +1,30 @@
-namespace HandyControlDemo.UserControl
+using System.Windows;
+using HandyControlDemo.Data;
+
+namespace HandyControlDemo.UserControl
{
public partial class PropertyGridDemoCtl
{
public PropertyGridDemoCtl()
{
InitializeComponent();
+
+ DemoModel = new PropertyGridDemoModel
+ {
+ Name = "TestName",
+ Gender = Gender.Female,
+ IsPassed = true,
+ Score = 98
+ };
+ }
+
+ public static readonly DependencyProperty DemoModelProperty = DependencyProperty.Register(
+ "DemoModel", typeof(PropertyGridDemoModel), typeof(PropertyGridDemoCtl), new PropertyMetadata(default(PropertyGridDemoModel)));
+
+ public PropertyGridDemoModel DemoModel
+ {
+ get => (PropertyGridDemoModel) GetValue(DemoModelProperty);
+ set => SetValue(DemoModelProperty, value);
}
}
}
diff --git a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/PlainTextPropertyEditor.cs b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/PlainTextPropertyEditor.cs
index 8011ebe8..7782e114 100644
--- a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/PlainTextPropertyEditor.cs
+++ b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/PlainTextPropertyEditor.cs
@@ -1,5 +1,4 @@
using System.Windows;
-using System.Windows.Data;
namespace HandyControl.Controls
{
@@ -11,7 +10,5 @@ namespace HandyControl.Controls
};
public override DependencyProperty GetDependencyProperty() => System.Windows.Controls.TextBox.TextProperty;
-
- public override BindingMode GetBindingMode(PropertyItem propertyItem) => BindingMode.OneWay;
}
}
\ 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 c1a7ab07..42a7a360 100644
--- a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/PropertyEditorBase.cs
+++ b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/PropertyEditorBase.cs
@@ -14,7 +14,7 @@ namespace HandyControl.Controls
Source = propertyItem.Value,
Mode = GetBindingMode(propertyItem),
UpdateSourceTrigger = GetUpdateSourceTrigger(propertyItem),
- Converter = GetConverter()
+ Converter = GetConverter(propertyItem)
});
public abstract DependencyProperty GetDependencyProperty();
@@ -23,6 +23,6 @@ namespace HandyControl.Controls
public virtual UpdateSourceTrigger GetUpdateSourceTrigger(PropertyItem propertyItem) => UpdateSourceTrigger.PropertyChanged;
- protected virtual IValueConverter GetConverter() => null;
+ protected virtual IValueConverter GetConverter(PropertyItem propertyItem) => null;
}
}
\ No newline at end of file
diff --git a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/ReadOnlyTextPropertyEditor.cs b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/ReadOnlyTextPropertyEditor.cs
index 05656d48..e88f10d5 100644
--- a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/ReadOnlyTextPropertyEditor.cs
+++ b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/Editors/ReadOnlyTextPropertyEditor.cs
@@ -1,5 +1,6 @@
using System.Windows;
using System.Windows.Data;
+using HandyControl.Tools;
namespace HandyControl.Controls
{
@@ -13,5 +14,7 @@ namespace HandyControl.Controls
public override DependencyProperty GetDependencyProperty() => System.Windows.Controls.TextBox.TextProperty;
public override BindingMode GetBindingMode(PropertyItem propertyItem) => BindingMode.OneWay;
+
+ protected override IValueConverter GetConverter(PropertyItem propertyItem) => ResourceHelper.GetResource("Object2StringConverter");
}
}
\ 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 846edc55..be9bfc25 100644
--- a/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyItem.cs
+++ b/src/Shared/HandyControl_Shared/Controls/PropertyGrid/PropertyItem.cs
@@ -1,4 +1,5 @@
using System;
+using System.ComponentModel;
using System.Windows;
using System.Windows.Controls;
@@ -123,6 +124,8 @@ namespace HandyControl.Controls
set => SetValue(IsExpandedEnabledProperty, value);
}
+ public PropertyDescriptor PropertyDescriptor { get; set; }
+
public virtual void InitElement()
{
if (Editor == null) return;
diff --git a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems
index 28ce3087..c0b60db6 100644
--- a/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems
+++ b/src/Shared/HandyControl_Shared/HandyControl_Shared.projitems
@@ -110,6 +110,7 @@
+
diff --git a/src/Shared/HandyControl_Shared/Themes/Basic/Converters.xaml b/src/Shared/HandyControl_Shared/Themes/Basic/Converters.xaml
index 209ee47b..97245b65 100644
--- a/src/Shared/HandyControl_Shared/Themes/Basic/Converters.xaml
+++ b/src/Shared/HandyControl_Shared/Themes/Basic/Converters.xaml
@@ -23,6 +23,7 @@
-
-
+
+
+
\ No newline at end of file
diff --git a/src/Shared/HandyControl_Shared/Tools/Converter/Object2StringConverter.cs b/src/Shared/HandyControl_Shared/Tools/Converter/Object2StringConverter.cs
new file mode 100644
index 00000000..48b9b2e5
--- /dev/null
+++ b/src/Shared/HandyControl_Shared/Tools/Converter/Object2StringConverter.cs
@@ -0,0 +1,16 @@
+using System;
+using System.Globalization;
+using System.Windows.Data;
+
+namespace HandyControl.Tools.Converter
+{
+ public class Object2StringConverter : IValueConverter
+ {
+ public object Convert(object value, Type targetType, object parameter, CultureInfo culture) => value?.ToString();
+
+ public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
+ {
+ throw new NotImplementedException();
+ }
+ }
+}