From 2a5d70e95b79c31d9cfa0fadf6b0eaf1de3f9f91 Mon Sep 17 00:00:00 2001 From: shaosu <1763319552@qq.com> Date: Mon, 3 May 2021 16:53:38 +0800 Subject: [PATCH 1/2] =?UTF-8?q?Maximum=E6=94=B9=E5=8F=98=E6=97=B6=E4=BC=9A?= =?UTF-8?q?=E5=BD=B1=E5=93=8D=E5=88=B0Value=E7=9A=84=E6=98=BE=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit MaximumProperty应设置独立的回调 --- .../HandyControl_Shared/Controls/Other/Badge.cs | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/Shared/HandyControl_Shared/Controls/Other/Badge.cs b/src/Shared/HandyControl_Shared/Controls/Other/Badge.cs index 06864f12a..fb2cdb26e 100644 --- a/src/Shared/HandyControl_Shared/Controls/Other/Badge.cs +++ b/src/Shared/HandyControl_Shared/Controls/Other/Badge.cs @@ -63,8 +63,15 @@ public BadgeStatus Status } public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register( - "Maximum", typeof(int), typeof(Badge), new PropertyMetadata(ValueBoxes.Int99Box, OnValueChanged)); - + "Maximum", typeof(int), typeof(Badge), new PropertyMetadata(ValueBoxes.Int99Box, OnMaximumValueChanged)); + + private static void OnMaximumValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + { + var ctl = (Badge) d; + var v = ctl.Value; + ctl.SetCurrentValue(TextProperty, v <= ctl.Maximum ? v.ToString() : $"{ctl.Maximum}+"); + } + public int Maximum { get => (int) GetValue(MaximumProperty); From 9f07f98d730140b7aef9382b97eba4d1dedf377e Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Tue, 22 Jun 2021 21:26:27 +0800 Subject: [PATCH 2/2] rename OnMaximumValueChanged to OnMaximumChanged --- src/Shared/HandyControl_Shared/Controls/Other/Badge.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Shared/HandyControl_Shared/Controls/Other/Badge.cs b/src/Shared/HandyControl_Shared/Controls/Other/Badge.cs index fb2cdb26e..038465b87 100644 --- a/src/Shared/HandyControl_Shared/Controls/Other/Badge.cs +++ b/src/Shared/HandyControl_Shared/Controls/Other/Badge.cs @@ -63,9 +63,9 @@ public BadgeStatus Status } public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register( - "Maximum", typeof(int), typeof(Badge), new PropertyMetadata(ValueBoxes.Int99Box, OnMaximumValueChanged)); + "Maximum", typeof(int), typeof(Badge), new PropertyMetadata(ValueBoxes.Int99Box, OnMaximumChanged)); - private static void OnMaximumValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) + private static void OnMaximumChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) { var ctl = (Badge) d; var v = ctl.Value;