diff --git a/HandyControl/Controls/Attach/LinkElement.cs b/HandyControl/Controls/Attach/LinkElement.cs new file mode 100644 index 00000000..90bd8053 --- /dev/null +++ b/HandyControl/Controls/Attach/LinkElement.cs @@ -0,0 +1,48 @@ +using System.Diagnostics; +using System.Windows; +using System.Windows.Input; +using HandyControl.Interactivity; + +namespace HandyControl.Controls +{ + public class LinkElement + { + public static readonly DependencyProperty LinkProperty = DependencyProperty.RegisterAttached( + "Link", typeof(string), typeof(LinkElement), new PropertyMetadata(default(string), OnLinkChanged)); + + private static void OnLinkChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + if (d is UIElement element) + { + CreateTrriger(element, (string) e.NewValue); + } + } + + private static readonly DependencyProperty CommandBindingProperty = DependencyProperty.RegisterAttached( + "CommandBinding", typeof(CommandBinding), typeof(LinkElement), new PropertyMetadata(default(CommandBinding))); + + private static void SetCommandBinding(DependencyObject element, CommandBinding value) + => element.SetValue(CommandBindingProperty, value); + + private static CommandBinding GetCommandBinding(DependencyObject element) + => (CommandBinding) element.GetValue(CommandBindingProperty); + + private static void CreateTrriger(UIElement element, string link) + { + if (string.IsNullOrEmpty(link)) + { + element.CommandBindings.Remove(GetCommandBinding(element)); + return; + } + var commandBinding = new CommandBinding(ControlCommands.OpenLink, (sender, args) => Process.Start(link)); + SetCommandBinding(element, commandBinding); + element.CommandBindings.Add(commandBinding); + } + + public static void SetLink(DependencyObject element, string value) + => element.SetValue(LinkProperty, value); + + public static string GetLink(DependencyObject element) + => (string) element.GetValue(LinkProperty); + } +} \ No newline at end of file diff --git a/HandyControl/Controls/Other/CircleProgressBar.cs b/HandyControl/Controls/Other/CircleProgressBar.cs index bcefe80c..474ced46 100644 --- a/HandyControl/Controls/Other/CircleProgressBar.cs +++ b/HandyControl/Controls/Other/CircleProgressBar.cs @@ -11,17 +11,28 @@ namespace HandyControl.Controls private const string IndicatorTemplateName = "PART_Indicator"; public static readonly DependencyProperty ArcThicknessProperty = DependencyProperty.Register( - "ArcThickness", typeof(double), typeof(CircleProgressBar), new PropertyMetadata(.0)); + "ArcThickness", typeof(double), typeof(CircleProgressBar), new PropertyMetadata(ValueBoxes.Double0Box)); public static readonly DependencyProperty ShowTextProperty = DependencyProperty.Register( "ShowText", typeof(bool), typeof(CircleProgressBar), new PropertyMetadata(ValueBoxes.TrueBox)); + public static readonly DependencyProperty TextProperty = DependencyProperty.Register( + "Text", typeof(string), typeof(CircleProgressBar), new PropertyMetadata(default(string))); + private Arc _indicator; static CircleProgressBar() { - FocusableProperty.OverrideMetadata(typeof(CircleProgressBar), new FrameworkPropertyMetadata(ValueBoxes.FalseBox)); - MaximumProperty.OverrideMetadata(typeof(CircleProgressBar), new FrameworkPropertyMetadata(ValueBoxes.Double100Box)); + FocusableProperty.OverrideMetadata(typeof(CircleProgressBar), + new FrameworkPropertyMetadata(ValueBoxes.FalseBox)); + MaximumProperty.OverrideMetadata(typeof(CircleProgressBar), + new FrameworkPropertyMetadata(ValueBoxes.Double100Box)); + } + + public string Text + { + get => (string) GetValue(TextProperty); + set => SetValue(TextProperty, value); } public bool ShowText diff --git a/HandyControl/Controls/Other/Shield.cs b/HandyControl/Controls/Other/Shield.cs new file mode 100644 index 00000000..28a5284a --- /dev/null +++ b/HandyControl/Controls/Other/Shield.cs @@ -0,0 +1,38 @@ +using System.Windows; +using System.Windows.Controls.Primitives; +using System.Windows.Markup; +using System.Windows.Media; + +namespace HandyControl.Controls +{ + [ContentProperty(nameof(Status))] + public class Shield : ButtonBase + { + public static readonly DependencyProperty SubjectProperty = DependencyProperty.Register( + "Subject", typeof(string), typeof(Shield), new PropertyMetadata(default(string))); + + public string Subject + { + get => (string) GetValue(SubjectProperty); + set => SetValue(SubjectProperty, value); + } + + public static readonly DependencyProperty StatusProperty = DependencyProperty.Register( + "Status", typeof(object), typeof(Shield), new PropertyMetadata(default(object))); + + public object Status + { + get => GetValue(StatusProperty); + set => SetValue(StatusProperty, value); + } + + public static readonly DependencyProperty ColorProperty = DependencyProperty.Register( + "Color", typeof(Brush), typeof(Shield), new PropertyMetadata(default(Brush))); + + public Brush Color + { + get => (Brush) GetValue(ColorProperty); + set => SetValue(ColorProperty, value); + } + } +} \ No newline at end of file diff --git a/HandyControl/Controls/Rate/Rate.cs b/HandyControl/Controls/Rate/Rate.cs index e2595971..d41d3256 100644 --- a/HandyControl/Controls/Rate/Rate.cs +++ b/HandyControl/Controls/Rate/Rate.cs @@ -4,11 +4,45 @@ using System.Windows.Controls; using System.Windows.Input; using System.Windows.Media; using HandyControl.Data; +using HandyControl.Tools; namespace HandyControl.Controls { public class Rate : ItemsControl { + public static readonly DependencyProperty ItemMarginProperty = DependencyProperty.Register( + "ItemMargin", typeof(Thickness), typeof(Rate), new PropertyMetadata(default(Thickness))); + + public static readonly DependencyProperty ItemWidthProperty = DependencyProperty.Register( + "ItemWidth", typeof(double), typeof(Rate), new PropertyMetadata(ValueBoxes.Double20Box)); + + public static readonly DependencyProperty ItemHeightProperty = DependencyProperty.Register( + "ItemHeight", typeof(double), typeof(Rate), new PropertyMetadata(ValueBoxes.Double20Box)); + + public static readonly DependencyProperty AllowHalfProperty = DependencyProperty.Register( + "AllowHalf", typeof(bool), typeof(Rate), new FrameworkPropertyMetadata(ValueBoxes.FalseBox, FrameworkPropertyMetadataOptions.Inherits)); + + public static readonly DependencyProperty AllowClearProperty = DependencyProperty.Register( + "AllowClear", typeof(bool), typeof(Rate), new FrameworkPropertyMetadata(ValueBoxes.TrueBox, FrameworkPropertyMetadataOptions.Inherits)); + + public static readonly DependencyProperty IconProperty = DependencyProperty.Register( + "Icon", typeof(Geometry), typeof(Rate), new FrameworkPropertyMetadata(default(Geometry), FrameworkPropertyMetadataOptions.Inherits)); + + public static readonly DependencyProperty CountProperty = DependencyProperty.Register( + "Count", typeof(int), typeof(Rate), new PropertyMetadata(ValueBoxes.Int5Box)); + + public static readonly DependencyProperty DefaultValueProperty = DependencyProperty.Register( + "DefaultValue", typeof(double), typeof(Rate), new PropertyMetadata(ValueBoxes.Double0Box)); + + public static readonly DependencyProperty ValueProperty = DependencyProperty.Register( + "Value", typeof(double), typeof(Rate), new PropertyMetadata(ValueBoxes.Double0Box)); + + public static readonly DependencyProperty TextProperty = DependencyProperty.Register( + "Text", typeof(string), typeof(Rate), new PropertyMetadata(default(string))); + + public static readonly DependencyProperty ShowTextProperty = DependencyProperty.Register( + "ShowText", typeof(bool), typeof(Rate), new PropertyMetadata(ValueBoxes.FalseBox)); + private bool _isLoaded; public Rate() @@ -18,6 +52,7 @@ namespace HandyControl.Controls Loaded += (s, e) => { + if (DesignerHelper.IsInDesignMode()) return; if (_isLoaded) return; _isLoaded = true; if (Value <= 0) @@ -35,15 +70,84 @@ namespace HandyControl.Controls }; } - private void RateItemValueChanged(object sender, RoutedEventArgs e) => Value = - (from RateItem item in Items where item.IsSelected select item.IsHalf ? 0.5 : 1).Sum(); + public Thickness ItemMargin + { + get => (Thickness) GetValue(ItemMarginProperty); + set => SetValue(ItemMarginProperty, value); + } + + public double ItemWidth + { + get => (double) GetValue(ItemWidthProperty); + set => SetValue(ItemWidthProperty, value); + } + + public double ItemHeight + { + get => (double) GetValue(ItemHeightProperty); + set => SetValue(ItemHeightProperty, value); + } + + public bool AllowHalf + { + get => (bool) GetValue(AllowHalfProperty); + set => SetValue(AllowHalfProperty, value); + } + + public bool AllowClear + { + get => (bool) GetValue(AllowClearProperty); + set => SetValue(AllowClearProperty, value); + } + + public Geometry Icon + { + get => (Geometry) GetValue(IconProperty); + set => SetValue(IconProperty, value); + } + + public int Count + { + get => (int) GetValue(CountProperty); + set => SetValue(CountProperty, value); + } + + public double DefaultValue + { + get => (double) GetValue(DefaultValueProperty); + set => SetValue(DefaultValueProperty, value); + } + + public double Value + { + get => (double) GetValue(ValueProperty); + set => SetValue(ValueProperty, value); + } + + public string Text + { + get => (string) GetValue(TextProperty); + set => SetValue(TextProperty, value); + } + + public bool ShowText + { + get => (bool) GetValue(ShowTextProperty); + set => SetValue(ShowTextProperty, value); + } + + private void RateItemValueChanged(object sender, RoutedEventArgs e) + { + Value = + (from RateItem item in Items where item.IsSelected select item.IsHalf ? 0.5 : 1).Sum(); + } private void RateItemSelectedChanged(object sender, RoutedEventArgs e) { if (e.OriginalSource is RateItem rateItem) { var index = rateItem.Index; - for (int i = 0; i < index; i++) + for (var i = 0; i < index; i++) { if (Items[i] is RateItem item) { @@ -51,7 +155,8 @@ namespace HandyControl.Controls item.IsHalf = false; } } - for (int i = index; i < Count; i++) + + for (var i = index; i < Count; i++) { if (Items[i] is RateItem item) { @@ -62,109 +167,16 @@ namespace HandyControl.Controls } } - public static readonly DependencyProperty ItemMarginProperty = DependencyProperty.Register( - "ItemMargin", typeof(Thickness), typeof(Rate), new PropertyMetadata(default(Thickness))); - - public Thickness ItemMargin + protected override bool IsItemItsOwnContainerOverride(object item) { - get => (Thickness)GetValue(ItemMarginProperty); - set => SetValue(ItemMarginProperty, value); + return item is RateItem; } - public static readonly DependencyProperty ItemWidthProperty = DependencyProperty.Register( - "ItemWidth", typeof(double), typeof(Rate), new PropertyMetadata(ValueBoxes.Double20Box)); - - public double ItemWidth + protected override DependencyObject GetContainerForItemOverride() { - get => (double)GetValue(ItemWidthProperty); - set => SetValue(ItemWidthProperty, value); + return new RateItem(); } - public static readonly DependencyProperty ItemHeightProperty = DependencyProperty.Register( - "ItemHeight", typeof(double), typeof(Rate), new PropertyMetadata(ValueBoxes.Double20Box)); - - public double ItemHeight - { - get => (double)GetValue(ItemHeightProperty); - set => SetValue(ItemHeightProperty, value); - } - - public static readonly DependencyProperty AllowHalfProperty = DependencyProperty.Register( - "AllowHalf", typeof(bool), typeof(Rate), new PropertyMetadata(ValueBoxes.FalseBox)); - - public bool AllowHalf - { - get => (bool)GetValue(AllowHalfProperty); - set => SetValue(AllowHalfProperty, value); - } - - public static readonly DependencyProperty AllowClearProperty = DependencyProperty.Register( - "AllowClear", typeof(bool), typeof(Rate), new PropertyMetadata(ValueBoxes.TrueBox)); - - public bool AllowClear - { - get => (bool)GetValue(AllowClearProperty); - set => SetValue(AllowClearProperty, value); - } - - public static readonly DependencyProperty IconProperty = DependencyProperty.Register( - "Icon", typeof(Geometry), typeof(Rate), new PropertyMetadata(default(Geometry))); - - public Geometry Icon - { - get => (Geometry)GetValue(IconProperty); - set => SetValue(IconProperty, value); - } - - public static readonly DependencyProperty CountProperty = DependencyProperty.Register( - "Count", typeof(int), typeof(Rate), new PropertyMetadata(ValueBoxes.Int5Box)); - - public int Count - { - get => (int)GetValue(CountProperty); - set => SetValue(CountProperty, value); - } - - public static readonly DependencyProperty DefaultValueProperty = DependencyProperty.Register( - "DefaultValue", typeof(double), typeof(Rate), new PropertyMetadata(ValueBoxes.Double0Box)); - - public double DefaultValue - { - get => (double)GetValue(DefaultValueProperty); - set => SetValue(DefaultValueProperty, value); - } - - public static readonly DependencyProperty ValueProperty = DependencyProperty.Register( - "Value", typeof(double), typeof(Rate), new PropertyMetadata(ValueBoxes.Double0Box)); - - public double Value - { - get => (double)GetValue(ValueProperty); - set => SetValue(ValueProperty, value); - } - - public static readonly DependencyProperty TextProperty = DependencyProperty.Register( - "Text", typeof(string), typeof(Rate), new PropertyMetadata(default(string))); - - public string Text - { - get => (string)GetValue(TextProperty); - set => SetValue(TextProperty, value); - } - - public static readonly DependencyProperty ShowTextProperty = DependencyProperty.Register( - "ShowText", typeof(bool), typeof(Rate), new PropertyMetadata(ValueBoxes.FalseBox)); - - public bool ShowText - { - get => (bool)GetValue(ShowTextProperty); - set => SetValue(ShowTextProperty, value); - } - - protected override bool IsItemItsOwnContainerOverride(object item) => item is RateItem; - - protected override DependencyObject GetContainerForItemOverride() => new RateItem(); - public override void OnApplyTemplate() { base.OnApplyTemplate(); @@ -173,7 +185,7 @@ namespace HandyControl.Controls { Items.Clear(); - for (int i = 1; i <= Count; i++) + for (var i = 1; i <= Count; i++) { Items.Add(new RateItem { @@ -192,8 +204,8 @@ namespace HandyControl.Controls private void UpdateItems() { - var count = (int)Value; - for (int i = 0; i < count; i++) + var count = (int) Value; + for (var i = 0; i < count; i++) { if (Items[i] is RateItem rateItem) { @@ -201,6 +213,7 @@ namespace HandyControl.Controls rateItem.IsHalf = false; } } + if (Value > count) { if (Items[count] is RateItem rateItem) @@ -208,9 +221,11 @@ namespace HandyControl.Controls rateItem.IsSelected = true; rateItem.IsHalf = true; } + count += 1; } - for (int i = count; i < Count; i++) + + for (var i = count; i < Count; i++) { if (Items[i] is RateItem rateItem) { @@ -220,6 +235,9 @@ namespace HandyControl.Controls } } - public void Reset() => Value = DefaultValue; + public void Reset() + { + Value = DefaultValue; + } } -} +} \ No newline at end of file diff --git a/HandyControl/Controls/Rate/RateItem.cs b/HandyControl/Controls/Rate/RateItem.cs index 383a61ea..ee50ffa3 100644 --- a/HandyControl/Controls/Rate/RateItem.cs +++ b/HandyControl/Controls/Rate/RateItem.cs @@ -12,86 +12,65 @@ namespace HandyControl.Controls { private const string ElementIcon = "PART_Icon"; - private FrameworkElement _icon; + public static readonly DependencyProperty AllowClearProperty = + Rate.AllowClearProperty.AddOwner(typeof(RateItem)); - private bool _isLoaded; + public static readonly DependencyProperty AllowHalfProperty = + Rate.AllowHalfProperty.AddOwner(typeof(RateItem), new PropertyMetadata(OnAllowHalfChanged)); - private bool _isSentValue; - - private bool _isMouseLeftButtonDown; - - public RateItem() => Loaded += (s, e) => _isLoaded = true; - - public static readonly DependencyProperty AllowClearProperty = DependencyProperty.Register( - "AllowClear", typeof(bool), typeof(RateItem), new PropertyMetadata(ValueBoxes.TrueBox)); - - public bool AllowClear - { - get => (bool)GetValue(AllowClearProperty); - set => SetValue(AllowClearProperty, value); - } - - public static readonly DependencyProperty AllowHalfProperty = DependencyProperty.Register( - "AllowHalf", typeof(bool), typeof(RateItem), new PropertyMetadata(ValueBoxes.FalseBox, OnAllowHalfChanged)); - - private static void OnAllowHalfChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - var ctl = (RateItem)d; - ctl.HandleMouseMoveEvent((bool)e.NewValue); - } - - public bool AllowHalf - { - get => (bool)GetValue(AllowHalfProperty); - set => SetValue(AllowHalfProperty, value); - } - - public static readonly DependencyProperty IconProperty = DependencyProperty.Register( - "Icon", typeof(Geometry), typeof(RateItem), new PropertyMetadata(default(Geometry))); - - public Geometry Icon - { - get => (Geometry)GetValue(IconProperty); - set => SetValue(IconProperty, value); - } + public static readonly DependencyProperty IconProperty = Rate.IconProperty.AddOwner(typeof(RateItem)); internal static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register( - "IsSelected", typeof(bool), typeof(RateItem), new PropertyMetadata(ValueBoxes.FalseBox, OnIsSelectedChanged)); - - private static void OnIsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) - { - var ctl = (RateItem)d; - ctl._icon.Show((bool)e.NewValue); - } - - internal bool IsSelected - { - get => (bool)GetValue(IsSelectedProperty); - set => SetValue(IsSelectedProperty, value); - } + "IsSelected", typeof(bool), typeof(RateItem), + new PropertyMetadata(ValueBoxes.FalseBox, OnIsSelectedChanged)); public static readonly RoutedEvent SelectedChangedEvent = EventManager.RegisterRoutedEvent("SelectedChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(RateItem)); - public event RoutedEventHandler SelectedChanged - { - add => AddHandler(SelectedChangedEvent, value); - remove => RemoveHandler(SelectedChangedEvent, value); - } - public static readonly RoutedEvent ValueChangedEvent = EventManager.RegisterRoutedEvent("ValueChanged", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(RateItem)); - public event RoutedEventHandler ValueChanged - { - add => AddHandler(ValueChangedEvent, value); - remove => RemoveHandler(ValueChangedEvent, value); - } + private FrameworkElement _icon; private bool _isHalf; + private bool _isLoaded; + + private bool _isMouseLeftButtonDown; + + private bool _isSentValue; + + public RateItem() + { + Loaded += (s, e) => _isLoaded = true; + } + + public bool AllowClear + { + get => (bool) GetValue(AllowClearProperty); + set => SetValue(AllowClearProperty, value); + } + + public bool AllowHalf + { + get => (bool) GetValue(AllowHalfProperty); + set => SetValue(AllowHalfProperty, value); + } + + public Geometry Icon + { + get => (Geometry) GetValue(IconProperty); + set => SetValue(IconProperty, value); + } + + internal bool IsSelected + { + get => (bool) GetValue(IsSelectedProperty); + set => SetValue(IsSelectedProperty, value); + } + internal bool IsHalf { get => _isHalf; @@ -105,6 +84,30 @@ namespace HandyControl.Controls internal int Index { get; set; } + private static void OnAllowHalfChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var ctl = (RateItem) d; + ctl.HandleMouseMoveEvent((bool) e.NewValue); + } + + private static void OnIsSelectedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var ctl = (RateItem) d; + ctl._icon.Show((bool) e.NewValue); + } + + public event RoutedEventHandler SelectedChanged + { + add => AddHandler(SelectedChangedEvent, value); + remove => RemoveHandler(SelectedChangedEvent, value); + } + + public event RoutedEventHandler ValueChanged + { + add => AddHandler(ValueChangedEvent, value); + remove => RemoveHandler(ValueChangedEvent, value); + } + private void HandleMouseMoveEvent(bool handle) { if (handle) @@ -144,7 +147,7 @@ namespace HandyControl.Controls _isSentValue = false; IsSelected = true; - RaiseEvent(new RoutedEventArgs(SelectedChangedEvent) { Source = this }); + RaiseEvent(new RoutedEventArgs(SelectedChangedEvent) {Source = this}); } protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e) @@ -178,6 +181,7 @@ namespace HandyControl.Controls _isSentValue = true; return; } + _isSentValue = false; IsSelected = false; IsHalf = false; diff --git a/HandyControl/HandyControl.csproj b/HandyControl/HandyControl.csproj index d28b79d8..5a45f7e2 100644 --- a/HandyControl/HandyControl.csproj +++ b/HandyControl/HandyControl.csproj @@ -92,6 +92,7 @@ + @@ -110,6 +111,7 @@ + @@ -202,6 +204,7 @@ + @@ -360,6 +363,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -368,6 +375,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -596,6 +607,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile diff --git a/HandyControl/Interactivity/ControlCommands.cs b/HandyControl/Interactivity/ControlCommands.cs index e74368fc..2054ff5b 100644 --- a/HandyControl/Interactivity/ControlCommands.cs +++ b/HandyControl/Interactivity/ControlCommands.cs @@ -131,5 +131,10 @@ namespace HandyControl.Interactivity /// 鼠标移动 /// public static RoutedCommand MouseMove { get; } = new RoutedCommand(nameof(MouseMove), typeof(ControlCommands)); + + /// + /// 打开链接 + /// + public static RoutedCommand OpenLink { get; } = new RoutedCommand(nameof(OpenLink), typeof(ControlCommands)); } } \ No newline at end of file diff --git a/HandyControl/Themes/Styles/Base/ProgressBarBaseStyle.xaml b/HandyControl/Themes/Styles/Base/ProgressBarBaseStyle.xaml index 4508be01..5e96b5cb 100644 --- a/HandyControl/Themes/Styles/Base/ProgressBarBaseStyle.xaml +++ b/HandyControl/Themes/Styles/Base/ProgressBarBaseStyle.xaml @@ -76,13 +76,14 @@ + - + diff --git a/HandyControl/Themes/Styles/Base/RateBaseStyle.xaml b/HandyControl/Themes/Styles/Base/RateBaseStyle.xaml index 9d29a661..95c61199 100644 --- a/HandyControl/Themes/Styles/Base/RateBaseStyle.xaml +++ b/HandyControl/Themes/Styles/Base/RateBaseStyle.xaml @@ -15,7 +15,6 @@ - diff --git a/HandyControl/Themes/Styles/Base/ShieldBaseStyle.xaml b/HandyControl/Themes/Styles/Base/ShieldBaseStyle.xaml new file mode 100644 index 00000000..dd4ffb4c --- /dev/null +++ b/HandyControl/Themes/Styles/Base/ShieldBaseStyle.xaml @@ -0,0 +1,39 @@ + + + + + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/Base/TreeViewBaseStyle.xaml b/HandyControl/Themes/Styles/Base/TreeViewBaseStyle.xaml new file mode 100644 index 00000000..63d2d8ab --- /dev/null +++ b/HandyControl/Themes/Styles/Base/TreeViewBaseStyle.xaml @@ -0,0 +1,142 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/Shield.xaml b/HandyControl/Themes/Styles/Shield.xaml new file mode 100644 index 00000000..e4c62e4e --- /dev/null +++ b/HandyControl/Themes/Styles/Shield.xaml @@ -0,0 +1,11 @@ + + + + + + + + - - + - - - - - - - - \ No newline at end of file diff --git a/HandyControl/Tools/Helper/DesignerHelper.cs b/HandyControl/Tools/Helper/DesignerHelper.cs new file mode 100644 index 00000000..1f4d3416 --- /dev/null +++ b/HandyControl/Tools/Helper/DesignerHelper.cs @@ -0,0 +1,61 @@ +using System; +using System.Linq; +using System.Reflection; + +namespace HandyControl.Tools +{ + public class DesignerHelper + { + public static bool IsInDesignMode() + { + try + { + var type1 = Type.GetType( + "System.ComponentModel.DesignerProperties, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + if (type1 == null) + return false; + var obj1 = type1.GetTypeInfo().GetDeclaredField("IsInDesignModeProperty").GetValue(null); + var type2 = Type.GetType( + "System.ComponentModel.DependencyPropertyDescriptor, WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + var type3 = Type.GetType( + "System.Windows.FrameworkElement, PresentationFramework, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + if (type2 == null || type3 == null) + return false; + var list = type2.GetTypeInfo().GetDeclaredMethods("FromProperty").ToList(); + if (list.Count == 0) + return false; + var methodInfo = list.FirstOrDefault(mi => + { + if (mi.IsPublic && mi.IsStatic) + return mi.GetParameters().Length == 2; + return false; + }); + if (methodInfo == null) + return false; + var obj2 = methodInfo.Invoke(null, new[] + { + obj1, + type3 + }); + if (obj2 == null) + return false; + var declaredProperty1 = type2.GetTypeInfo().GetDeclaredProperty("Metadata"); + if (declaredProperty1 == null) + return false; + var obj3 = declaredProperty1.GetValue(obj2, null); + var type4 = Type.GetType( + "System.Windows.PropertyMetadata, WindowsBase, Version=3.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"); + if (obj3 == null || type4 == null) + return false; + var declaredProperty2 = type4.GetTypeInfo().GetDeclaredProperty("DefaultValue"); + if (declaredProperty2 == null) + return false; + return (bool) declaredProperty2.GetValue(obj3, null); + } + catch + { + return false; + } + } + } +} \ No newline at end of file diff --git a/HandyControlDemo/Data/MessageToken.cs b/HandyControlDemo/Data/MessageToken.cs index 588a5b6d..81585c04 100644 --- a/HandyControlDemo/Data/MessageToken.cs +++ b/HandyControlDemo/Data/MessageToken.cs @@ -66,6 +66,8 @@ public static readonly string RateDemoCtl = nameof(RateDemoCtl); + public static readonly string ShieldDemoCtl = nameof(ShieldDemoCtl); + public static readonly string ButtonDemoCtl = nameof(ButtonDemoCtl); public static readonly string ToggleButtonDemoCtl = nameof(ToggleButtonDemoCtl); diff --git a/HandyControlDemo/Data/MessageToken.tt b/HandyControlDemo/Data/MessageToken.tt index f9ae0db6..8d998ceb 100644 --- a/HandyControlDemo/Data/MessageToken.tt +++ b/HandyControlDemo/Data/MessageToken.tt @@ -35,7 +35,8 @@ var controlList = new List "FlipClockDemoCtl", "QQGroupView", "BlurWindow", - "RateDemoCtl" + "RateDemoCtl", + "ShieldDemoCtl" }; var styleList = new List { diff --git a/HandyControlDemo/HandyControlDemo.csproj b/HandyControlDemo/HandyControlDemo.csproj index 87384aa3..7b854b59 100644 --- a/HandyControlDemo/HandyControlDemo.csproj +++ b/HandyControlDemo/HandyControlDemo.csproj @@ -171,6 +171,9 @@ SearchBarDemoCtl.xaml + + ShieldDemoCtl.xaml + StepBarDemoCtl.xaml @@ -455,6 +458,10 @@ Designer MSBuild:Compile + + Designer + MSBuild:Compile + Designer MSBuild:Compile @@ -647,6 +654,7 @@ TextTemplatingFileGenerator MessageToken.cs + diff --git a/HandyControlDemo/Properties/Langs/Lang.Designer.cs b/HandyControlDemo/Properties/Langs/Lang.Designer.cs index a4904768..37b055b6 100644 --- a/HandyControlDemo/Properties/Langs/Lang.Designer.cs +++ b/HandyControlDemo/Properties/Langs/Lang.Designer.cs @@ -825,6 +825,15 @@ namespace HandyControlDemo.Properties.Langs { } } + /// + /// 查找类似 徽章 的本地化字符串。 + /// + public static string Shield { + get { + return ResourceManager.GetString("Shield", resourceCulture); + } + } + /// /// 查找类似 显示行号 的本地化字符串。 /// diff --git a/HandyControlDemo/Properties/Langs/Lang.en.resx b/HandyControlDemo/Properties/Langs/Lang.en.resx index b3355a51..33e53c3e 100644 --- a/HandyControlDemo/Properties/Langs/Lang.en.resx +++ b/HandyControlDemo/Properties/Langs/Lang.en.resx @@ -447,4 +447,7 @@ Rate + + Shield + \ No newline at end of file diff --git a/HandyControlDemo/Properties/Langs/Lang.resx b/HandyControlDemo/Properties/Langs/Lang.resx index 218da9cf..f910452f 100644 --- a/HandyControlDemo/Properties/Langs/Lang.resx +++ b/HandyControlDemo/Properties/Langs/Lang.resx @@ -427,4 +427,7 @@ 评分 + + 徽章 + \ No newline at end of file diff --git a/HandyControlDemo/Resources/Img/LeftMainContent/Shield_16x.png b/HandyControlDemo/Resources/Img/LeftMainContent/Shield_16x.png new file mode 100644 index 00000000..9b30ef16 Binary files /dev/null and b/HandyControlDemo/Resources/Img/LeftMainContent/Shield_16x.png differ diff --git a/HandyControlDemo/UserControl/Controls/RateDemoCtl.xaml b/HandyControlDemo/UserControl/Controls/RateDemoCtl.xaml index 2fe07025..1f7e3524 100644 --- a/HandyControlDemo/UserControl/Controls/RateDemoCtl.xaml +++ b/HandyControlDemo/UserControl/Controls/RateDemoCtl.xaml @@ -6,6 +6,7 @@ + diff --git a/HandyControlDemo/UserControl/Controls/ShieldDemoCtl.xaml b/HandyControlDemo/UserControl/Controls/ShieldDemoCtl.xaml new file mode 100644 index 00000000..6676c3ef --- /dev/null +++ b/HandyControlDemo/UserControl/Controls/ShieldDemoCtl.xaml @@ -0,0 +1,16 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/HandyControlDemo/UserControl/Controls/ShieldDemoCtl.xaml.cs b/HandyControlDemo/UserControl/Controls/ShieldDemoCtl.xaml.cs new file mode 100644 index 00000000..6cfbc669 --- /dev/null +++ b/HandyControlDemo/UserControl/Controls/ShieldDemoCtl.xaml.cs @@ -0,0 +1,10 @@ +namespace HandyControlDemo.UserControl +{ + public partial class ShieldDemoCtl + { + public ShieldDemoCtl() + { + InitializeComponent(); + } + } +} diff --git a/HandyControlDemo/UserControl/Main/LeftMainContent.xaml b/HandyControlDemo/UserControl/Main/LeftMainContent.xaml index 6b51a723..a208902f 100644 --- a/HandyControlDemo/UserControl/Main/LeftMainContent.xaml +++ b/HandyControlDemo/UserControl/Main/LeftMainContent.xaml @@ -200,6 +200,11 @@ + + + + +