add partial codes

This commit is contained in:
NaBian committed 2020-06-15 00:24:18 +08:00
1 parent 507a44aa25
commit aeb5d2a3b8
37 files changed
+806 -4

No files matched your search

@@ -313,6 +313,9 @@
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\LeftMainContent\RadioButton_16x.png">
<Link>Resources\Img\LeftMainContent\RadioButton_16x.png</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\LeftMainContent\PropertyGridEditorPart_16x.png">
<Link>Resources\Img\LeftMainContent\PropertyGridEditorPart_16x.png</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\LeftMainContent\RepeatButton_16x.png">
<Link>Resources\Img\LeftMainContent\RepeatButton_16x.png</Link>
</Resource>
@@ -313,6 +313,9 @@
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\LeftMainContent\RadioButton_16x.png">
<Link>Resources\Img\LeftMainContent\RadioButton_16x.png</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\LeftMainContent\PropertyGridEditorPart_16x.png">
<Link>Resources\Img\LeftMainContent\PropertyGridEditorPart_16x.png</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\LeftMainContent\RepeatButton_16x.png">
<Link>Resources\Img\LeftMainContent\RepeatButton_16x.png</Link>
</Resource>
@@ -134,4 +134,7 @@
<Link>Resources\Images\GlowWindow\topright.png</Link>
</Resource>
</ItemGroup>
<ItemGroup>
<None Remove="..\..\Shared\HandyControl_Shared\Tools\Extension\CustomAttributeExtension.cs" />
</ItemGroup>
</Project>
@@ -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", "" ],
@@ -84,6 +84,9 @@
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Controls\PinBoxDemoCtl.xaml.cs">
<DependentUpon>PinBoxDemoCtl.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Controls\PropertyGridDemoCtl.xaml.cs">
<DependentUpon>PropertyGridDemoCtl.xaml</DependentUpon>
</Compile>
<Compile Include="$(MSBuildThisFileDirectory)UserControl\Controls\RangeSliderDemoCtl.xaml.cs">
<DependentUpon>RangeSliderDemoCtl.xaml</DependentUpon>
</Compile>
@@ -548,6 +551,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)UserControl\Controls\PropertyGridDemoCtl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)UserControl\Controls\RangeSliderDemoCtl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -1337,7 +1337,18 @@ namespace HandyControlDemo.Properties.Langs {
return ResourceManager.GetString("Project", resourceCulture);
}
}
/// <summary>
/// 查找类似 属性编辑器 的本地化字符串。
/// </summary>
public static string PropertyGrid
{
get
{
return ResourceManager.GetString("PropertyGrid", resourceCulture);
}
}
/// <summary>
/// 查找类似 按住说话 的本地化字符串。
/// </summary>
@@ -750,4 +750,7 @@
<data name="LangComment" xml:space="preserve">
<value>Looks up a localized string similar to "{0}".</value>
</data>
<data name="PropertyGrid" xml:space="preserve">
<value>PropertyGrid</value>
</data>
</root>
@@ -750,4 +750,7 @@
<data name="LangComment" xml:space="preserve">
<value>Looks up a localized string similar to "{0}".</value>
</data>
<data name="PropertyGrid" xml:space="preserve">
<value>PropertyGrid</value>
</data>
</root>
@@ -750,4 +750,7 @@
<data name="LangComment" xml:space="preserve">
<value>Looks up a localized string similar to "{0}".</value>
</data>
<data name="PropertyGrid" xml:space="preserve">
<value>PropertyGrid</value>
</data>
</root>
@@ -750,4 +750,7 @@
<data name="LangComment" xml:space="preserve">
<value>Looks up a localized string similar to "{0}".</value>
</data>
<data name="PropertyGrid" xml:space="preserve">
<value>PropertyGrid</value>
</data>
</root>
@@ -750,4 +750,7 @@
<data name="LangComment" xml:space="preserve">
<value>查找类似 {0} 的本地化字符串。</value>
</data>
<data name="PropertyGrid" xml:space="preserve">
<value>属性编辑器</value>
</data>
</root>
@@ -750,4 +750,7 @@
<data name="LangComment" xml:space="preserve">
<value>Looks up a localized string similar to "{0}".</value>
</data>
<data name="PropertyGrid" xml:space="preserve">
<value>PropertyGrid</value>
</data>
</root>
@@ -750,4 +750,7 @@
<data name="LangComment" xml:space="preserve">
<value>Looks up a localized string similar to "{0}".</value>
</data>
<data name="PropertyGrid" xml:space="preserve">
<value>PropertyGrid</value>
</data>
</root>
@@ -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
/// </summary>
public string Project => Lang.Project;
/// <summary>
/// 查找类似 属性编辑器 的本地化字符串。
/// </summary>
public string PropertyGrid => Lang.PropertyGrid;
/// <summary>
/// 查找类似 按住说话 的本地化字符串。
/// </summary>
@@ -2024,6 +2030,11 @@ namespace HandyControlDemo.Properties.Langs
/// </summary>
public static string Project = nameof(Project);
/// <summary>
/// 查找类似 属性编辑器 的本地化字符串。
/// </summary>
public static string PropertyGrid = nameof(PropertyGrid);
/// <summary>
/// 查找类似 按住说话 的本地化字符串。
/// </summary>
Binary file not shown.

After

Width:  |  Height:  |  Size: 173 B

@@ -0,0 +1,7 @@
<UserControl x:Class="HandyControlDemo.UserControl.PropertyGridDemoCtl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:userControl="clr-namespace:HandyControlDemo.UserControl"
Background="{DynamicResource RegionBrush}">
<userControl:UnderConstruction/>
</UserControl>
@@ -0,0 +1,10 @@
namespace HandyControlDemo.UserControl
{
public partial class PropertyGridDemoCtl
{
public PropertyGridDemoCtl()
{
InitializeComponent();
}
}
}
@@ -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<Style>("ToggleButtonSwitch"),
HorizontalAlignment = HorizontalAlignment.Left,
IsEnabled = !propertyItem.IsReadOnly
};
button.SetBinding(ToggleButton.IsCheckedProperty, CreateBinding(propertyItem));
return button;
}
}
}
@@ -0,0 +1,19 @@
using System.Windows;
namespace HandyControl.Controls
{
public class DateTimePropertyEditor : PropertyEditorBase
{
public override FrameworkElement CreateElement(PropertyItem propertyItem)
{
var picker = new DateTimePicker
{
IsEnabled = !propertyItem.IsReadOnly
};
picker.SetBinding(DateTimePicker.SelectedDateTimeProperty, CreateBinding(propertyItem));
return picker;
}
}
}
@@ -0,0 +1,31 @@
using System.Windows;
namespace HandyControl.Controls
{
public class IntegerPropertyEditor : PropertyEditorBase
{
public IntegerPropertyEditor(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;
}
}
}
@@ -0,0 +1,18 @@
using System.Windows;
using System.Windows.Data;
namespace HandyControl.Controls
{
public abstract class PropertyEditorBase : FrameworkElement
{
public abstract FrameworkElement CreateElement(PropertyItem propertyItem);
public virtual Binding CreateBinding(PropertyItem propertyItem) =>
new Binding(propertyItem.PropertyName)
{
Source = propertyItem.Value,
Mode = propertyItem.IsReadOnly ? BindingMode.OneWay : BindingMode.TwoWay,
UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged
};
}
}
@@ -0,0 +1,19 @@
using System.Windows;
namespace HandyControl.Controls
{
public class StringPropertyEditor : 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;
}
}
}
@@ -0,0 +1,103 @@
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using HandyControl.Tools.Extension;
namespace HandyControl.Controls
{
[TemplatePart(Name = ElementItemsControl, Type = typeof(ItemsControl))]
public class PropertyGrid : Control
{
private const string ElementItemsControl = "PART_ItemsControl";
private ItemsControl _itemsControl;
public virtual PropertyResolver PropertyResolver { get; } = new PropertyResolver();
public static readonly RoutedEvent SelectedObjectChangedEvent =
EventManager.RegisterRoutedEvent("SelectedObjectChanged", RoutingStrategy.Bubble,
typeof(RoutedPropertyChangedEventHandler<object>), typeof(PropertyGrid));
public event RoutedPropertyChangedEventHandler<object> SelectedObjectChanged
{
add => AddHandler(SelectedObjectChangedEvent, value);
remove => RemoveHandler(SelectedObjectChangedEvent, value);
}
public static readonly DependencyProperty SelectedObjectProperty = DependencyProperty.Register(
"SelectedObject", typeof(object), typeof(PropertyGrid), new PropertyMetadata(default, OnSelectedObjectChanged));
private static void OnSelectedObjectChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var ctl = (PropertyGrid)d;
ctl.OnSelectedObjectChanged(e.OldValue, e.NewValue);
}
public object SelectedObject
{
get => GetValue(SelectedObjectProperty);
set => SetValue(SelectedObjectProperty, value);
}
protected virtual void OnSelectedObjectChanged(object oldValue, object newValue)
{
UpdateItems(newValue);
RaiseEvent(new RoutedPropertyChangedEventArgs<object>(oldValue, newValue, SelectedObjectChangedEvent));
}
public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(
"Description", typeof(string), typeof(PropertyGrid), new PropertyMetadata(default(string)));
public string Description
{
get => (string)GetValue(DescriptionProperty);
set => SetValue(DescriptionProperty, value);
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_itemsControl = GetTemplateChild(ElementItemsControl) as ItemsControl;
UpdateItems(SelectedObject);
}
private void UpdateItems(object obj)
{
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;
var categorySet = new HashSet<string>();
foreach (var propertyItem in itemList)
{
categorySet.Add(propertyItem.Category);
}
var view = CollectionViewSource.GetDefaultView(itemList);
view.GroupDescriptions.Add(new PropertyGroupDescription("Category"));
}
protected virtual PropertyItem CreatePropertyItem(PropertyInfo propertyInfo) =>
new PropertyItem
{
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
};
}
}
@@ -0,0 +1,141 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
namespace HandyControl.Controls
{
public class PropertyItem : Control
{
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
"Value", typeof(object), typeof(PropertyItem), new PropertyMetadata(default(object)));
public object Value
{
get => GetValue(ValueProperty);
set => SetValue(ValueProperty, value);
}
public static readonly DependencyProperty DisplayNameProperty = DependencyProperty.Register(
"DisplayName", typeof(string), typeof(PropertyItem), new PropertyMetadata(default(string)));
public string DisplayName
{
get => (string)GetValue(DisplayNameProperty);
set => SetValue(DisplayNameProperty, value);
}
public static readonly DependencyProperty PropertyNameProperty = DependencyProperty.Register(
"PropertyName", typeof(string), typeof(PropertyItem), new PropertyMetadata(default(string)));
public string PropertyName
{
get => (string)GetValue(PropertyNameProperty);
set => SetValue(PropertyNameProperty, value);
}
public static readonly DependencyProperty PropertyTypeNameProperty = DependencyProperty.Register(
"PropertyTypeName", typeof(string), typeof(PropertyItem), new PropertyMetadata(default(string)));
public string PropertyTypeName
{
get => (string)GetValue(PropertyTypeNameProperty);
set => SetValue(PropertyTypeNameProperty, value);
}
public static readonly DependencyProperty DescriptionProperty = DependencyProperty.Register(
"Description", typeof(string), typeof(PropertyItem), new PropertyMetadata(default(string)));
public string Description
{
get => (string)GetValue(DescriptionProperty);
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)));
public bool IsReadOnly
{
get => (bool)GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
public static readonly DependencyProperty DefaultValueProperty = DependencyProperty.Register(
"DefaultValue", typeof(object), typeof(PropertyItem), new PropertyMetadata(default(object)));
public object DefaultValue
{
get => GetValue(DefaultValueProperty);
set => SetValue(DefaultValueProperty, value);
}
public static readonly DependencyProperty CategoryProperty = DependencyProperty.Register(
"Category", typeof(string), typeof(PropertyItem), new PropertyMetadata(default(string)));
public string Category
{
get => (string)GetValue(CategoryProperty);
set => SetValue(CategoryProperty, value);
}
public static readonly DependencyProperty EditorProperty = DependencyProperty.Register(
"Editor", typeof(PropertyEditorBase), typeof(PropertyItem), new PropertyMetadata(default(PropertyEditorBase)));
public PropertyEditorBase Editor
{
get => (PropertyEditorBase)GetValue(EditorProperty);
set => SetValue(EditorProperty, value);
}
public static readonly DependencyProperty EditorElementProperty = DependencyProperty.Register(
"EditorElement", typeof(FrameworkElement), typeof(PropertyItem), new PropertyMetadata(default(FrameworkElement)));
public FrameworkElement EditorElement
{
get => (FrameworkElement)GetValue(EditorElementProperty);
set => SetValue(EditorElementProperty, value);
}
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(
"IsSelected", typeof(bool), typeof(PropertyItem), new PropertyMetadata(default(bool)));
public bool IsSelected
{
get => (bool)GetValue(IsSelectedProperty);
set => SetValue(IsSelectedProperty, value);
}
public static readonly DependencyProperty IsExpandedEnabledProperty = DependencyProperty.Register(
"IsExpandedEnabled", typeof(bool), typeof(PropertyItem), new PropertyMetadata(default(bool)));
public bool IsExpandedEnabled
{
get => (bool)GetValue(IsExpandedEnabledProperty);
set => SetValue(IsExpandedEnabledProperty, value);
}
public static readonly DependencyProperty ConverterProperty = DependencyProperty.Register(
"Converter", typeof(IValueConverter), typeof(PropertyItem), new PropertyMetadata(default(IValueConverter)));
public IValueConverter Converter
{
get => (IValueConverter) GetValue(ConverterProperty);
set => SetValue(ConverterProperty, value);
}
public virtual void InitElement()
{
if (Editor == null) return;
EditorElement = Editor.CreateElement(this);
}
}
}
@@ -0,0 +1,9 @@
using System.Windows.Controls;
namespace HandyControl.Controls
{
public class PropertyItemsControl : ItemsControl
{
protected override bool IsItemItsOwnContainerOverride(object item) => item is PropertyItem;
}
}
@@ -0,0 +1,160 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Reflection;
using System.Windows.Data;
using HandyControl.Properties.Langs;
#if NET40
using HandyControl.Tools.Extension;
#endif
namespace HandyControl.Controls
{
public class PropertyResolver
{
private static readonly Dictionary<Type, EditorTypeCode> TypeCodeDic = new Dictionary<Type, EditorTypeCode>
{
[typeof(string)] = EditorTypeCode.PlainText,
[typeof(sbyte)] = EditorTypeCode.SByteNumber,
[typeof(byte)] = EditorTypeCode.ByteNumber,
[typeof(short)] = EditorTypeCode.Int16Number,
[typeof(ushort)] = EditorTypeCode.UInt16Number,
[typeof(int)] = EditorTypeCode.Int32Number,
[typeof(uint)] = EditorTypeCode.UInt32Number,
[typeof(long)] = EditorTypeCode.Int64Number,
[typeof(ulong)] = EditorTypeCode.UInt64Number,
[typeof(float)] = EditorTypeCode.SingleNumber,
[typeof(double)] = EditorTypeCode.DoubleNumber,
[typeof(bool)] = EditorTypeCode.Switch
};
public string ResolveCategory(PropertyInfo propertyInfo)
{
var categoryAttribute = propertyInfo.GetCustomAttribute<CategoryAttribute>();
string category;
if (categoryAttribute != null && !string.IsNullOrEmpty(categoryAttribute.Category))
{
category = categoryAttribute.Category;
}
else
{
category = Lang.Miscellaneous;
}
return category;
}
public string ResolveDisplayName(PropertyInfo propertyInfo)
{
var displayNameAttribute = propertyInfo.GetCustomAttribute<DisplayNameAttribute>();
string displayName;
if (displayNameAttribute != null && !string.IsNullOrEmpty(displayNameAttribute.DisplayName))
{
displayName = displayNameAttribute.DisplayName;
}
else
{
displayName = propertyInfo.Name;
}
return displayName;
}
public string ResolveDescription(PropertyInfo propertyInfo)
{
var descriptionAttribute = propertyInfo.GetCustomAttribute<DescriptionAttribute>();
string description;
if (descriptionAttribute != null && !string.IsNullOrEmpty(descriptionAttribute.Description))
{
description = descriptionAttribute.Description;
}
else
{
description = string.Empty;
}
return description;
}
public bool ResolveBrowsable(PropertyInfo propertyInfo)
{
var browsableAttribute = propertyInfo.GetCustomAttribute<BrowsableAttribute>();
return browsableAttribute == null || browsableAttribute.Browsable;
}
public bool ResolveIsReadOnly(PropertyInfo propertyInfo)
{
var isReadOnlyAttribute = propertyInfo.GetCustomAttribute<ReadOnlyAttribute>();
return isReadOnlyAttribute != null && isReadOnlyAttribute.IsReadOnly;
}
public object ResolveDefaultValue(PropertyInfo propertyInfo)
{
var defaultValueAttribute = propertyInfo.GetCustomAttribute<DefaultValueAttribute>();
return defaultValueAttribute?.Value;
}
public IValueConverter ResolveConverter(PropertyInfo propertyInfo)
{
var typeConverterAttribute = propertyInfo.GetCustomAttribute<TypeConverterAttribute>();
if (typeConverterAttribute != null && !string.IsNullOrEmpty(typeConverterAttribute.ConverterTypeName))
{
return CreateTypeConverter(Type.GetType(typeConverterAttribute.ConverterTypeName));
}
return null;
}
public virtual IValueConverter CreateTypeConverter(Type type) => Activator.CreateInstance(type) as IValueConverter;
public PropertyEditorBase ResolveEditor(PropertyInfo propertyInfo)
{
var editorAttribute = propertyInfo.GetCustomAttribute<EditorAttribute>();
var editor = editorAttribute == null || string.IsNullOrEmpty(editorAttribute.EditorTypeName)
? CreateDefaultEditor(propertyInfo.PropertyType)
: CreateEditor(Type.GetType(editorAttribute.EditorTypeName));
return editor;
}
public virtual PropertyEditorBase CreateDefaultEditor(Type type) =>
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.DateTime => new DateTimePropertyEditor(),
_ => new StringPropertyEditor()
})
: new StringPropertyEditor();
public virtual PropertyEditorBase CreateEditor(Type type) => new StringPropertyEditor();
private enum EditorTypeCode
{
PlainText,
SByteNumber,
ByteNumber,
Int16Number,
UInt16Number,
Int32Number,
UInt32Number,
Int64Number,
UInt64Number,
SingleNumber,
DoubleNumber,
Switch,
DateTime
}
}
}
@@ -40,6 +40,15 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Notification.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Poptip.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Watermark.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\PropertyGrid\Editors\BooleanPropertyEditor.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\PropertyGrid\Editors\DateTimePropertyEditor.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\PropertyGrid\Editors\PropertyEditorBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\PropertyGrid\Editors\IntegerPropertyEditor.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\PropertyGrid\Editors\StringPropertyEditor.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\PropertyGrid\PropertyGrid.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\PropertyGrid\PropertyItem.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\PropertyGrid\PropertyItemsControl.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\PropertyGrid\PropertyResolver.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Screenshot\Screenshot.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Other\Sprite.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Controls\Block\ToggleBlock.cs" />
@@ -99,6 +108,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\Number2PercentageConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\RectangleCircularConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\ThicknessSplitConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Extension\CustomAttributeExtension.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Extension\DependencyObjectExtension.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Extension\FrameworkElementExtension.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Extension\LangExtension.cs" />
@@ -419,6 +429,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Themes\Styles\Base\PropertyGridBaseStyle.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="$(MSBuildThisFileDirectory)Themes\Styles\Watermark.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -266,7 +266,18 @@ namespace HandyControl.Properties.Langs {
return ResourceManager.GetString("LangComment", resourceCulture);
}
}
/// <summary>
/// 查找类似 杂项 的本地化字符串。
/// </summary>
public static string Miscellaneous
{
get
{
return ResourceManager.GetString("Miscellaneous", resourceCulture);
}
}
/// <summary>
/// 查找类似 下一页 的本地化字符串。
/// </summary>
@@ -234,4 +234,7 @@
<data name="Jump" xml:space="preserve">
<value>Jump</value>
</data>
<data name="Miscellaneous" xml:space="preserve">
<value>Miscellaneous</value>
</data>
</root>
@@ -234,4 +234,7 @@
<data name="Jump" xml:space="preserve">
<value>Jump</value>
</data>
<data name="Miscellaneous" xml:space="preserve">
<value>Miscellaneous</value>
</data>
</root>
@@ -234,4 +234,7 @@
<data name="Jump" xml:space="preserve">
<value>Jump</value>
</data>
<data name="Miscellaneous" xml:space="preserve">
<value>Miscellaneous</value>
</data>
</root>
@@ -234,4 +234,7 @@
<data name="Jump" xml:space="preserve">
<value>Jump</value>
</data>
<data name="Miscellaneous" xml:space="preserve">
<value>Miscellaneous</value>
</data>
</root>
@@ -234,4 +234,7 @@
<data name="Jump" xml:space="preserve">
<value>跳转</value>
</data>
<data name="Miscellaneous" xml:space="preserve">
<value>杂项</value>
</data>
</root>
@@ -234,4 +234,7 @@
<data name="Jump" xml:space="preserve">
<value>Jump</value>
</data>
<data name="Miscellaneous" xml:space="preserve">
<value>Miscellaneous</value>
</data>
</root>
@@ -234,4 +234,7 @@
<data name="Jump" xml:space="preserve">
<value>Jump</value>
</data>
<data name="Miscellaneous" xml:space="preserve">
<value>Miscellaneous</value>
</data>
</root>
@@ -0,0 +1,144 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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">
<ResourceDictionary.MergedDictionaries>
<themes:SharedResourceDictionary Source="pack://application:,,,/HandyControl;component/Themes/Styles/GroupBox.xaml"/>
</ResourceDictionary.MergedDictionaries>
<DrawingBrush x:Key="SortByCategoryDrawingBrush" o:Freeze="True">
<DrawingBrush.Drawing>
<DrawingGroup o:Freeze="True">
<GeometryDrawing o:Freeze="True" Brush="#00FFFFFF" Geometry="F1M16,16L0,16 0,0 16,0z" />
<GeometryDrawing o:Freeze="True" Brush="#FFF6F6F6" Geometry="F1M0.9999,-0.000199999999999534L0.9999,15.9998 10.9999,15.9998 10.9999,13.4148 11.9999,14.4138 15.9999,10.4138 15.9999,5.5858 14.0009,7.5858 14.0009,3.0008 10.9999,3.0008 10.9999,-0.000199999999999534z" />
<GeometryDrawing o:Freeze="True" Brush="#FF424242" Geometry="F1M10,12.4141L10,15.0001 2,15.0001 2,1.0001 10,1.0001 10,3.0001 10,7.5861 8.414,6.0001 9,6.0001 9,3.0001 3,3.0001 3,6.0001 8,6.0001 8,7.0001 3,7.0001 3,10.0001 8,10.0001 8,10.4141 8.586,11.0001 3,11.0001 3,14.0001 9,14.0001 9,11.4141z" />
<GeometryDrawing o:Freeze="True" Brush="#FFEFEFF0" Geometry="F1M8.5859,11L2.9999,11 2.9999,14 8.9999,14 8.9999,11.414z M7.9999,7L2.9999,7 2.9999,10 7.9999,10z M7.9999,6L2.9999,6 2.9999,3 8.9999,3 8.9999,6 8.4139,6 7.9999,5.586z" />
<GeometryDrawing o:Freeze="True" Brush="#FF00529C" Geometry="F1M13,10L13,4 11,4 11,10 9,8 9,10 12,13 15,10 15,8z" />
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
<DrawingBrush x:Key="SortAscendingDrawingBrush" o:Freeze="True">
<DrawingBrush.Drawing>
<DrawingGroup o:Freeze="True">
<GeometryDrawing o:Freeze="True" Brush="#00FFFFFF" Geometry="F1M16,16L0,16 0,0 16,0z" />
<GeometryDrawing o:Freeze="True" Brush="#FFF6F6F6" Geometry="F1M0,-0.000199999999999534L0,8.9998 1,8.9998 1,12.0008 2.586,12.0008 1,13.5858 1,15.9998 8,15.9998 8,13.0008 6.449,13.0008 8,12.0008 8,10.9998 12,14.9998 16,10.9998 16,4.9998 14,6.9998 14,3.0008 10,3.0008 10,6.9998 9,5.9998 9,-0.000199999999999534z" />
<GeometryDrawing o:Freeze="True" Brush="#FF424242" Geometry="F1M7,7L5,2 4,2 2,7 3,7 3.399,6 5.601,6 6,7z M8,8L1,8 1,1 8,1z M4.5,3.25L5.2,5 3.8,5z M2,11L5,11 2,14 2,15 7,15 7,14 4.013,14 7,11.051 6.952,11 7,11 7,10 2,10z" />
<GeometryDrawing o:Freeze="True" Brush="#FFEFEFF0" Geometry="F1M3.7998,5L4.4998,3.25 5.1998,5z M5.9998,7L6.9998,7 4.9998,2 3.9998,2 1.9998,7 2.9998,7 3.3998,6 5.6008,6z" />
<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>
<Style x:Key="PropertyItemToolTipBaseStyle" BasedOn="{StaticResource {x:Type ToolTip}}" TargetType="ToolTip">
<Setter Property="Padding" Value="10"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ToolTip">
<Border Background="{DynamicResource RegionBrush}" Padding="{TemplateBinding Padding}" BorderThickness="1" CornerRadius="{Binding Path=(hc:BorderElement.CornerRadius),RelativeSource={RelativeSource TemplatedParent}}" BorderBrush="{DynamicResource BorderBrush}">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<ContentPresenter x:Name="Presenter" Margin="0,0,0,10"/>
<StackPanel Grid.Row="1" Orientation="Horizontal">
<TextBlock FontWeight="Bold" Text="{Binding PropertyTypeName,RelativeSource={RelativeSource AncestorType=hc:PropertyItem}}"/>
<TextBlock Text="{Binding PropertyName,RelativeSource={RelativeSource AncestorType=hc:PropertyItem}}" Margin="6,0,0,0"/>
</StackPanel>
</Grid>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="Content" Value="{x:Null}">
<Setter TargetName="Presenter" Property="Visibility" Value="Collapsed"/>
</Trigger>
<Trigger Property="Content" Value="">
<Setter TargetName="Presenter" Property="Visibility" Value="Collapsed"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="PropertyItemBaseStyle" TargetType="hc:PropertyItem">
<Setter Property="Focusable" Value="False"/>
<Setter Property="Margin" Value="0,0,0,6"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="hc:PropertyItem">
<GroupBox Style="{StaticResource GroupBoxOriginal}" hc:TitleElement.TitlePlacement="Left">
<GroupBox.Header>
<TextBlock Text="{TemplateBinding DisplayName}">
<TextBlock.ToolTip>
<ToolTip Style="{StaticResource PropertyItemToolTipBaseStyle}" Content="{TemplateBinding Description}"/>
</TextBlock.ToolTip>
</TextBlock>
</GroupBox.Header>
<ContentPresenter ContentSource="EditorElement"/>
</GroupBox>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style x:Key="PropertyGroupItemBaseStyle" TargetType="GroupItem">
<Setter Property="Margin" Value="0,0,0,6"/>
<Setter Property="Padding" Value="10,10,6,4"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="GroupItem">
<Expander BorderThickness="1" BorderBrush="{DynamicResource BorderBrush}" Header="{Binding Name}" IsExpanded="True" Background="{DynamicResource ThirdlyRegionBrush}" Foreground="{DynamicResource PrimaryTextBrush}">
<Border BorderThickness="1,0,1,1" BorderBrush="{DynamicResource BorderBrush}" Background="{DynamicResource SecondaryRegionBrush}" CornerRadius="0,0,4,4">
<ItemsPresenter Margin="{TemplateBinding Padding}"/>
</Border>
</Expander>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Style TargetType="hc:PropertyGrid">
<Setter Property="Focusable" Value="False"/>
<Setter Property="Padding" Value="10"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="hc:PropertyGrid">
<Border Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
<Grid Margin="{TemplateBinding Padding}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<DockPanel LastChildFill="True">
<hc:ButtonGroup>
<RadioButton>
<Viewbox Width="16" Height="16">
<Rectangle Width="16" Height="16" Fill="{StaticResource SortByCategoryDrawingBrush}"/>
</Viewbox>
</RadioButton>
<RadioButton>
<Viewbox Width="16" Height="16">
<Rectangle Width="16" Height="16" Fill="{StaticResource SortAscendingDrawingBrush}"/>
</Viewbox>
</RadioButton>
</hc:ButtonGroup>
<hc:SearchBar Margin="6,0,0,6"/>
</DockPanel>
<ScrollViewer Grid.Row="1">
<hc:PropertyItemsControl x:Name="PART_ItemsControl" Focusable="False" ItemContainerStyle="{StaticResource PropertyItemBaseStyle}">
<hc:PropertyItemsControl.GroupStyle>
<GroupStyle ContainerStyle="{StaticResource PropertyGroupItemBaseStyle}"/>
</hc:PropertyItemsControl.GroupStyle>
</hc:PropertyItemsControl>
</ScrollViewer>
</Grid>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
@@ -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<T>(this MemberInfo element) where T : Attribute => (T)GetCustomAttribute(element, typeof(T));
}
}