From bf34643ff46caf634a53f3b2ac8e56f5153402d3 Mon Sep 17 00:00:00 2001 From: Dingping Zhang Date: Thu, 4 Apr 2019 13:19:32 +0800 Subject: [PATCH] Add the processing status style to badge control. --- HandyControl/Controls/Other/Badge.cs | 24 +++--- .../Themes/Styles/Base/BadgeBaseStyle.xaml | 76 ++++++++++++++----- .../UserControl/Controls/BadgeDemoCtl.xaml | 5 +- 3 files changed, 72 insertions(+), 33 deletions(-) diff --git a/HandyControl/Controls/Other/Badge.cs b/HandyControl/Controls/Other/Badge.cs index 85e85c8b..4660d97c 100644 --- a/HandyControl/Controls/Other/Badge.cs +++ b/HandyControl/Controls/Other/Badge.cs @@ -4,6 +4,8 @@ using HandyControl.Data; namespace HandyControl.Controls { + public enum BadgeStatus { Normal, Dot, Processing } + /// /// 标记 /// @@ -14,7 +16,7 @@ namespace HandyControl.Controls public string Text { - get => (string) GetValue(TextProperty); + get => (string)GetValue(TextProperty); set => SetValue(TextProperty, value); } @@ -23,24 +25,24 @@ namespace HandyControl.Controls private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { - var ctl = (Badge) d; - var v = (int) e.NewValue; + var ctl = (Badge)d; + var v = (int)e.NewValue; ctl.Text = v <= ctl.Maximum ? v.ToString() : $"{ctl.Maximum}+"; } public int Value { - get => (int) GetValue(ValueProperty); + get => (int)GetValue(ValueProperty); set => SetValue(ValueProperty, value); } - public static readonly DependencyProperty IsDotProperty = DependencyProperty.Register( - "IsDot", typeof(bool), typeof(Badge), new PropertyMetadata(ValueBoxes.FalseBox)); + public static readonly DependencyProperty StatusProperty = DependencyProperty.Register( + "Status", typeof(BadgeStatus), typeof(Badge), new PropertyMetadata(default(BadgeStatus))); - public bool IsDot + public BadgeStatus Status { - get => (bool) GetValue(IsDotProperty); - set => SetValue(IsDotProperty, value); + get => (BadgeStatus)GetValue(StatusProperty); + set => SetValue(StatusProperty, value); } public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register( @@ -48,7 +50,7 @@ namespace HandyControl.Controls public int Maximum { - get => (int) GetValue(MaximumProperty); + get => (int)GetValue(MaximumProperty); set => SetValue(MaximumProperty, value); } @@ -57,7 +59,7 @@ namespace HandyControl.Controls public Thickness BadgeMargin { - get => (Thickness) GetValue(BadgeMarginProperty); + get => (Thickness)GetValue(BadgeMarginProperty); set => SetValue(BadgeMarginProperty, value); } } diff --git a/HandyControl/Themes/Styles/Base/BadgeBaseStyle.xaml b/HandyControl/Themes/Styles/Base/BadgeBaseStyle.xaml index d1e7d26e..7bde9499 100644 --- a/HandyControl/Themes/Styles/Base/BadgeBaseStyle.xaml +++ b/HandyControl/Themes/Styles/Base/BadgeBaseStyle.xaml @@ -1,42 +1,76 @@ - + - + - + - + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/HandyControlDemo/UserControl/Controls/BadgeDemoCtl.xaml b/HandyControlDemo/UserControl/Controls/BadgeDemoCtl.xaml index 5fd1ed85..3039e7b2 100644 --- a/HandyControlDemo/UserControl/Controls/BadgeDemoCtl.xaml +++ b/HandyControlDemo/UserControl/Controls/BadgeDemoCtl.xaml @@ -18,9 +18,12 @@