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 @@
-
-
+
+
diff --git a/HandyControlDemo/ViewModel/Controls/BadgeDemoCtlViewModel.cs b/HandyControlDemo/ViewModel/Controls/BadgeDemoCtlViewModel.cs
new file mode 100644
index 00000000..c12fd36b
--- /dev/null
+++ b/HandyControlDemo/ViewModel/Controls/BadgeDemoCtlViewModel.cs
@@ -0,0 +1,25 @@
+using System.Windows.Input;
+using GalaSoft.MvvmLight;
+using GalaSoft.MvvmLight.CommandWpf;
+
+namespace HandyControlDemo.ViewModel.Controls
+{
+ public class BadgeDemoCtlViewModel : ViewModelBase
+ {
+ private int _count;
+
+ public int Count
+ {
+ get => _count;
+ set => Set(ref _count, value);
+ }
+
+ public ICommand CountCommand { get; }
+
+ public BadgeDemoCtlViewModel()
+ {
+ Count = 1;
+ CountCommand = new RelayCommand(() => Count++);
+ }
+ }
+}
diff --git a/HandyControlDemo/ViewModel/ViewModelLocator.cs b/HandyControlDemo/ViewModel/ViewModelLocator.cs
index 24997587..d6386eb0 100644
--- a/HandyControlDemo/ViewModel/ViewModelLocator.cs
+++ b/HandyControlDemo/ViewModel/ViewModelLocator.cs
@@ -5,6 +5,7 @@ using GalaSoft.MvvmLight.Ioc;
using HandyControlDemo.Data;
using HandyControlDemo.Service;
using HandyControlDemo.ViewModel.Basic;
+using HandyControlDemo.ViewModel.Controls;
namespace HandyControlDemo.ViewModel
{
@@ -31,6 +32,7 @@ namespace HandyControlDemo.ViewModel
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
SimpleIoc.Default.Register();
+ SimpleIoc.Default.Register();
}
public static ViewModelLocator Instance => new Lazy(() =>
@@ -67,6 +69,8 @@ namespace HandyControlDemo.ViewModel
public NotifyIconDemoViewModel NotifyIconDemo => ServiceLocator.Current.GetInstance();
public InteractiveDialogViewModel InteractiveDialog => ServiceLocator.Current.GetInstance();
+
+ public BadgeDemoCtlViewModel BadgeDemoCtl => ServiceLocator.Current.GetInstance();
#endregion
}
}
\ No newline at end of file