From 2fd5d904326ad8b9190ed049aa00f17b2bdade0f Mon Sep 17 00:00:00 2001 From: DingpingZhang Date: Thu, 4 Apr 2019 21:05:15 +0800 Subject: [PATCH] Play an animation when the content of the badge is changed, and add the related demo. --- HandyControl/Controls/Other/Badge.cs | 17 +++++++++- .../Themes/Styles/Base/BadgeBaseStyle.xaml | 32 +++++++++++++++++-- HandyControlDemo/HandyControlDemo.csproj | 1 + .../UserControl/Controls/BadgeDemoCtl.xaml | 7 ++-- .../Controls/BadgeDemoCtlViewModel.cs | 25 +++++++++++++++ .../ViewModel/ViewModelLocator.cs | 4 +++ 6 files changed, 79 insertions(+), 7 deletions(-) create mode 100644 HandyControlDemo/ViewModel/Controls/BadgeDemoCtlViewModel.cs diff --git a/HandyControl/Controls/Other/Badge.cs b/HandyControl/Controls/Other/Badge.cs index 4660d97c..bd02d2bf 100644 --- a/HandyControl/Controls/Other/Badge.cs +++ b/HandyControl/Controls/Other/Badge.cs @@ -11,8 +11,23 @@ namespace HandyControl.Controls /// public class Badge : ContentControl { + public static readonly RoutedEvent BadgeChangedEvent = EventManager.RegisterRoutedEvent( + "BadgeChanged", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(Badge)); + + public event RoutedEventHandler BadgeChanged + { + add => AddHandler(BadgeChangedEvent, value); + remove => RemoveHandler(BadgeChangedEvent, value); + } + public static readonly DependencyProperty TextProperty = DependencyProperty.Register( - "Text", typeof(string), typeof(Badge), new PropertyMetadata(default(string))); + "Text", typeof(string), typeof(Badge), new PropertyMetadata(default(string), (o, args) => + { + var ctl = (Badge)o; + + if (ctl.IsInitialized) + ctl.RaiseEvent(new RoutedEventArgs(BadgeChangedEvent, ctl)); + })); public string Text { diff --git a/HandyControl/Themes/Styles/Base/BadgeBaseStyle.xaml b/HandyControl/Themes/Styles/Base/BadgeBaseStyle.xaml index 7bde9499..15b47890 100644 --- a/HandyControl/Themes/Styles/Base/BadgeBaseStyle.xaml +++ b/HandyControl/Themes/Styles/Base/BadgeBaseStyle.xaml @@ -4,13 +4,41 @@ + + - + + + + + + + + + + + + + + + @@ -20,8 +48,6 @@ - - diff --git a/HandyControlDemo/HandyControlDemo.csproj b/HandyControlDemo/HandyControlDemo.csproj index 9bfba767..c663153c 100644 --- a/HandyControlDemo/HandyControlDemo.csproj +++ b/HandyControlDemo/HandyControlDemo.csproj @@ -364,6 +364,7 @@ + diff --git a/HandyControlDemo/UserControl/Controls/BadgeDemoCtl.xaml b/HandyControlDemo/UserControl/Controls/BadgeDemoCtl.xaml index 3039e7b2..9cf1eec8 100644 --- a/HandyControlDemo/UserControl/Controls/BadgeDemoCtl.xaml +++ b/HandyControlDemo/UserControl/Controls/BadgeDemoCtl.xaml @@ -3,7 +3,8 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:HandyControl.Controls;assembly=HandyControl" xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs" - Background="{DynamicResource RegionBrush}"> + Background="{DynamicResource RegionBrush}" + DataContext="{Binding Path=BadgeDemoCtl, Source={StaticResource Locator}}"> @@ -12,8 +13,8 @@