fix: fixed #1115
This commit is contained in:
1 parent
38a68d3074
commit
25f3ec0e03
1 file changed
+22
-1
@@ -11,6 +11,8 @@ namespace HandyControl.Controls;
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
public class Badge : ContentControl
|
public class Badge : ContentControl
|
||||||
{
|
{
|
||||||
|
private int? _originalValue;
|
||||||
|
|
||||||
public static readonly RoutedEvent ValueChangedEvent =
|
public static readonly RoutedEvent ValueChangedEvent =
|
||||||
EventManager.RegisterRoutedEvent("ValueChanged", RoutingStrategy.Bubble,
|
EventManager.RegisterRoutedEvent("ValueChanged", RoutingStrategy.Bubble,
|
||||||
typeof(EventHandler<FunctionEventArgs<int>>), typeof(Badge));
|
typeof(EventHandler<FunctionEventArgs<int>>), typeof(Badge));
|
||||||
@@ -38,13 +40,17 @@ public class Badge : ContentControl
|
|||||||
var ctl = (Badge) d;
|
var ctl = (Badge) d;
|
||||||
var v = (int) e.NewValue;
|
var v = (int) e.NewValue;
|
||||||
ctl.SetCurrentValue(TextProperty, v <= ctl.Maximum ? v.ToString() : $"{ctl.Maximum}+");
|
ctl.SetCurrentValue(TextProperty, v <= ctl.Maximum ? v.ToString() : $"{ctl.Maximum}+");
|
||||||
if (ctl.IsInitialized)
|
if (ctl.IsLoaded)
|
||||||
{
|
{
|
||||||
ctl.RaiseEvent(new FunctionEventArgs<int>(ValueChangedEvent, ctl)
|
ctl.RaiseEvent(new FunctionEventArgs<int>(ValueChangedEvent, ctl)
|
||||||
{
|
{
|
||||||
Info = v
|
Info = v
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
ctl._originalValue = v;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public int Value
|
public int Value
|
||||||
@@ -97,4 +103,19 @@ public class Badge : ContentControl
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected override Geometry GetLayoutClip(Size layoutSlotSize) => null;
|
protected override Geometry GetLayoutClip(Size layoutSlotSize) => null;
|
||||||
|
|
||||||
|
public override void OnApplyTemplate()
|
||||||
|
{
|
||||||
|
base.OnApplyTemplate();
|
||||||
|
|
||||||
|
if (_originalValue != null)
|
||||||
|
{
|
||||||
|
RaiseEvent(new FunctionEventArgs<int>(ValueChangedEvent, this)
|
||||||
|
{
|
||||||
|
Info = _originalValue.Value
|
||||||
|
});
|
||||||
|
|
||||||
|
_originalValue = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user