From b27391b88caa65dd1f0ff3745a6a1d95daa99536 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Mon, 23 Sep 2019 22:45:03 +0800 Subject: [PATCH] fixed #179 --- .../HandyControl_Shared/Controls/Rate/Rate.cs | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/src/Shared/HandyControl_Shared/Controls/Rate/Rate.cs b/src/Shared/HandyControl_Shared/Controls/Rate/Rate.cs index 45665b8d..7e15f681 100644 --- a/src/Shared/HandyControl_Shared/Controls/Rate/Rate.cs +++ b/src/Shared/HandyControl_Shared/Controls/Rate/Rate.cs @@ -1,4 +1,5 @@ -using System.Linq; +using System; +using System.Linq; using System.Windows; using System.Windows.Input; using System.Windows.Media; @@ -31,7 +32,15 @@ namespace HandyControl.Controls "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)); + "Value", typeof(double), typeof(Rate), new PropertyMetadata(ValueBoxes.Double0Box, OnValueChanged)); + + private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) => + ((Rate) d).OnValueChanged(new FunctionEventArgs(ValueChangedEvent, d) + { + Info = (double)e.NewValue + }); + + protected virtual void OnValueChanged(FunctionEventArgs e) => RaiseEvent(e); public static readonly DependencyProperty TextProperty = DependencyProperty.Register( "Text", typeof(string), typeof(Rate), new PropertyMetadata(default(string))); @@ -46,6 +55,20 @@ namespace HandyControl.Controls private bool _updateItems; + #region Public Events + + public static readonly RoutedEvent ValueChangedEvent = + EventManager.RegisterRoutedEvent("ValueChanged", RoutingStrategy.Bubble, + typeof(EventHandler>), typeof(Rate)); + + public event EventHandler> ValueChanged + { + add => AddHandler(ValueChangedEvent, value); + remove => RemoveHandler(ValueChangedEvent, value); + } + + #endregion Public Events + public Rate() { AddHandler(RateItem.SelectedChangedEvent, new RoutedEventHandler(RateItemSelectedChanged));