12 files changed
+318
-198
No files matched your search
@@ -1,4 +1,5 @@
|
||||
using System.Windows;
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using HandyControl.Data;
|
||||
|
||||
@@ -9,6 +10,16 @@ namespace HandyControl.Controls
|
||||
/// </summary>
|
||||
public class Badge : ContentControl
|
||||
{
|
||||
public static readonly RoutedEvent ValueChangedEvent =
|
||||
EventManager.RegisterRoutedEvent("ValueChanged", RoutingStrategy.Bubble,
|
||||
typeof(EventHandler<FunctionEventArgs<int>>), typeof(Badge));
|
||||
|
||||
public event EventHandler<FunctionEventArgs<int>> ValueChanged
|
||||
{
|
||||
add => AddHandler(ValueChangedEvent, value);
|
||||
remove => RemoveHandler(ValueChangedEvent, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
|
||||
"Text", typeof(string), typeof(Badge), new PropertyMetadata(default(string)));
|
||||
|
||||
@@ -23,24 +34,31 @@ namespace HandyControl.Controls
|
||||
|
||||
private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var ctl = (Badge) d;
|
||||
var v = (int) e.NewValue;
|
||||
var ctl = (Badge)d;
|
||||
var v = (int)e.NewValue;
|
||||
ctl.Text = v <= ctl.Maximum ? v.ToString() : $"{ctl.Maximum}+";
|
||||
if (ctl.IsInitialized)
|
||||
{
|
||||
ctl.RaiseEvent(new FunctionEventArgs<int>(ValueChangedEvent, ctl)
|
||||
{
|
||||
Info = v
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
public int Value
|
||||
{
|
||||
get => (int) GetValue(ValueProperty);
|
||||
get => (int)GetValue(ValueProperty);
|
||||
set => SetValue(ValueProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsDotProperty = DependencyProperty.Register(
|
||||
"IsDot", typeof(bool), typeof(Badge), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||
public static readonly DependencyProperty StatusProperty = DependencyProperty.Register(
|
||||
"Status", typeof(BadgeStatus), typeof(Badge), new PropertyMetadata(default(BadgeStatus)));
|
||||
|
||||
public bool IsDot
|
||||
public BadgeStatus Status
|
||||
{
|
||||
get => (bool) GetValue(IsDotProperty);
|
||||
set => SetValue(IsDotProperty, value);
|
||||
get => (BadgeStatus)GetValue(StatusProperty);
|
||||
set => SetValue(StatusProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register(
|
||||
@@ -48,7 +66,7 @@ namespace HandyControl.Controls
|
||||
|
||||
public int Maximum
|
||||
{
|
||||
get => (int) GetValue(MaximumProperty);
|
||||
get => (int)GetValue(MaximumProperty);
|
||||
set => SetValue(MaximumProperty, value);
|
||||
}
|
||||
|
||||
@@ -57,7 +75,7 @@ namespace HandyControl.Controls
|
||||
|
||||
public Thickness BadgeMargin
|
||||
{
|
||||
get => (Thickness) GetValue(BadgeMarginProperty);
|
||||
get => (Thickness)GetValue(BadgeMarginProperty);
|
||||
set => SetValue(BadgeMarginProperty, value);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Input;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Interactivity;
|
||||
using HandyControl.Tools;
|
||||
|
||||
@@ -12,7 +13,7 @@ namespace HandyControl.Controls
|
||||
private Adorner _container;
|
||||
|
||||
public static readonly DependencyProperty IsClosedProperty = DependencyProperty.Register(
|
||||
"IsClosed", typeof(bool), typeof(Dialog), new PropertyMetadata(default(bool)));
|
||||
"IsClosed", typeof(bool), typeof(Dialog), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||
|
||||
public bool IsClosed
|
||||
{
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace HandyControl.Data
|
||||
{
|
||||
public enum BadgeStatus
|
||||
{
|
||||
Text,
|
||||
Dot,
|
||||
Processing
|
||||
}
|
||||
}
|
||||
@@ -165,6 +165,7 @@
|
||||
<Compile Include="Controls\Window\BlurWindow.cs" />
|
||||
<Compile Include="Controls\Window\MessageBox.cs" />
|
||||
<Compile Include="Data\Args\CancelRoutedEventArgs.cs" />
|
||||
<Compile Include="Data\Enum\BadgeStatus.cs" />
|
||||
<Compile Include="Data\Enum\ChatMessageType.cs" />
|
||||
<Compile Include="Data\Enum\ChatRoleType.cs" />
|
||||
<Compile Include="Data\Enum\InfoType.cs" />
|
||||
|
||||
@@ -1,42 +1,89 @@
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
|
||||
xmlns:controls="clr-namespace:HandyControl.Controls">
|
||||
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:HandyControl.Controls">
|
||||
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="../Border.xaml"/>
|
||||
<ResourceDictionary Source="../Border.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<SineEase x:Key="SineEaseOut" EasingMode="EaseOut" />
|
||||
|
||||
<ControlTemplate x:Key="BadgeTextTemplate" TargetType="controls:Badge">
|
||||
<controls:SimplePanel>
|
||||
<ContentPresenter/>
|
||||
<Border Style="{StaticResource BorderCircular}" Margin="{TemplateBinding BadgeMargin}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
|
||||
<ContentPresenter ContentSource="Text" Margin="{TemplateBinding Padding}"/>
|
||||
<ContentPresenter />
|
||||
<Border x:Name="Border" RenderTransformOrigin="0.5 0.5" Style="{StaticResource BorderCircular}" Margin="{TemplateBinding BadgeMargin}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}">
|
||||
<Border.RenderTransform>
|
||||
<ScaleTransform />
|
||||
</Border.RenderTransform>
|
||||
<ContentPresenter ContentSource="Text" Margin="{TemplateBinding Padding}" />
|
||||
</Border>
|
||||
</controls:SimplePanel>
|
||||
<ControlTemplate.Triggers>
|
||||
<EventTrigger RoutedEvent="controls:Badge.ValueChanged">
|
||||
<BeginStoryboard>
|
||||
<Storyboard AutoReverse="True">
|
||||
<DoubleAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)" BeginTime="0" Duration="0:0:.1" From="1" To="1.2" EasingFunction="{StaticResource SineEaseOut}" />
|
||||
<DoubleAnimation Storyboard.TargetName="Border" Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" BeginTime="0" Duration="0:0:.1" From="1" To="1.2" EasingFunction="{StaticResource SineEaseOut}" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</EventTrigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
|
||||
<ControlTemplate x:Key="BadgeDotTemplate" TargetType="controls:Badge">
|
||||
<controls:SimplePanel>
|
||||
<ContentPresenter/>
|
||||
<Border Margin="{TemplateBinding BadgeMargin}" Width="10" Height="10" CornerRadius="5" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}"/>
|
||||
<ContentPresenter />
|
||||
<Border Margin="{TemplateBinding BadgeMargin}" Width="10" Height="10" CornerRadius="5" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" />
|
||||
</controls:SimplePanel>
|
||||
</ControlTemplate>
|
||||
|
||||
<ControlTemplate x:Key="BadgeProcessingTemplate" TargetType="controls:Badge">
|
||||
<controls:SimplePanel>
|
||||
<ContentPresenter />
|
||||
<Ellipse Height="10" Width="10" Fill="{TemplateBinding Background}" RenderTransformOrigin="0.5 0.5" Margin="{TemplateBinding BadgeMargin}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
|
||||
<Ellipse.OpacityMask>
|
||||
<RadialGradientBrush>
|
||||
<GradientStop Offset="0" Color="Transparent" />
|
||||
<GradientStop Offset="1" Color="Black" />
|
||||
</RadialGradientBrush>
|
||||
</Ellipse.OpacityMask>
|
||||
<Ellipse.RenderTransform>
|
||||
<ScaleTransform />
|
||||
</Ellipse.RenderTransform>
|
||||
<Ellipse.Triggers>
|
||||
<EventTrigger RoutedEvent="Loaded">
|
||||
<BeginStoryboard>
|
||||
<Storyboard RepeatBehavior="Forever">
|
||||
<DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleX)" BeginTime="0" Duration="0:0:1" From="1" To="2" EasingFunction="{StaticResource SineEaseOut}" />
|
||||
<DoubleAnimation Storyboard.TargetProperty="(UIElement.RenderTransform).(ScaleTransform.ScaleY)" BeginTime="0" Duration="0:0:1" From="1" To="2" EasingFunction="{StaticResource SineEaseOut}" />
|
||||
<DoubleAnimation Storyboard.TargetProperty="Opacity" BeginTime="0" Duration="0:0:1" From="1" To="0" EasingFunction="{StaticResource SineEaseOut}" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</EventTrigger>
|
||||
</Ellipse.Triggers>
|
||||
</Ellipse>
|
||||
<Border Margin="{TemplateBinding BadgeMargin}" Width="10" Height="10" CornerRadius="5" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" />
|
||||
</controls:SimplePanel>
|
||||
</ControlTemplate>
|
||||
|
||||
<Style x:Key="BadgeBaseStyle" TargetType="controls:Badge">
|
||||
<Setter Property="Background" Value="{DynamicResource SecondaryRegionBrush}"/>
|
||||
<Setter Property="Foreground" Value="{DynamicResource TextIconBrush}"/>
|
||||
<Setter Property="BorderThickness" Value="1"/>
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource RegionBrush}"/>
|
||||
<Setter Property="Padding" Value="6,2"/>
|
||||
<Setter Property="Template" Value="{StaticResource BadgeTextTemplate}"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Right"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Top"/>
|
||||
<Setter Property="BadgeMargin" Value="0,-10,-10,0"/>
|
||||
<Setter Property="Background" Value="{DynamicResource SecondaryRegionBrush}" />
|
||||
<Setter Property="Foreground" Value="{DynamicResource TextIconBrush}" />
|
||||
<Setter Property="BorderThickness" Value="1" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource RegionBrush}" />
|
||||
<Setter Property="Padding" Value="6,2" />
|
||||
<Setter Property="Template" Value="{StaticResource BadgeTextTemplate}" />
|
||||
<Setter Property="HorizontalContentAlignment" Value="Right" />
|
||||
<Setter Property="VerticalContentAlignment" Value="Top" />
|
||||
<Setter Property="BadgeMargin" Value="0,-10,-10,0" />
|
||||
<Style.Triggers>
|
||||
<Trigger Property="IsDot" Value="True">
|
||||
<Setter Property="Template" Value="{StaticResource BadgeDotTemplate}"/>
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
|
||||
<Setter Property="BadgeMargin" Value="0,-5,-5,0"/>
|
||||
<Trigger Property="Status" Value="Dot">
|
||||
<Setter Property="Template" Value="{StaticResource BadgeDotTemplate}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}" />
|
||||
<Setter Property="BadgeMargin" Value="0,-5,-5,0" />
|
||||
</Trigger>
|
||||
<Trigger Property="Status" Value="Processing">
|
||||
<Setter Property="Template" Value="{StaticResource BadgeProcessingTemplate}" />
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}" />
|
||||
<Setter Property="BadgeMargin" Value="0,-5,-5,0" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
|
||||
@@ -364,6 +364,7 @@
|
||||
<Compile Include="ViewModel\Basic\ChatBoxViewModel.cs" />
|
||||
<Compile Include="ViewModel\Basic\InteractiveDialogViewModel.cs" />
|
||||
<Compile Include="ViewModel\Common\ComboBoxDemoViewModel.cs" />
|
||||
<Compile Include="ViewModel\Controls\BadgeDemoViewModel.cs" />
|
||||
<Compile Include="ViewModel\Controls\CoverViewModel.cs" />
|
||||
<Compile Include="ViewModel\Controls\DialogDemoViewModel.cs" />
|
||||
<Compile Include="ViewModel\Controls\NotifyIconDemoViewModel.cs" />
|
||||
|
||||
+169
-160
File diff suppressed because it is too large.
Load diff
@@ -561,4 +561,7 @@
|
||||
<data name="PleaseInput" xml:space="preserve">
|
||||
<value>Please input...</value>
|
||||
</data>
|
||||
<data name="Click2Count" xml:space="preserve">
|
||||
<value>Click to count</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -561,4 +561,7 @@
|
||||
<data name="PleaseInput" xml:space="preserve">
|
||||
<value>请输入...</value>
|
||||
</data>
|
||||
<data name="Click2Count" xml:space="preserve">
|
||||
<value>点击计数</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -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 BadgeDemo, Source={StaticResource Locator}}">
|
||||
<controls:TransitioningContentControl>
|
||||
<StackPanel Margin="32" Orientation="Horizontal">
|
||||
<controls:Badge Text="New" BadgeMargin="0,-14,-20,0" Height="30">
|
||||
@@ -12,15 +13,18 @@
|
||||
<controls:Badge Text="New" BadgeMargin="0,-14,-20,0" Height="30" Margin="32,0,0,0" Style="{StaticResource BadgeDanger}">
|
||||
<Button Content="{x:Static langs:Lang.Comment}"/>
|
||||
</controls:Badge>
|
||||
<controls:Badge Value="1" Height="30" Margin="32,0,0,0" Style="{StaticResource BadgePrimary}">
|
||||
<Button Content="{x:Static langs:Lang.Comment}"/>
|
||||
<controls:Badge Value="{Binding Count}" BadgeMargin="0,-14,-10,0" Height="30" Margin="32,0,0,0" Style="{StaticResource BadgePrimary}">
|
||||
<Button Content="{x:Static langs:Lang.Click2Count}" Command="{Binding CountCmd}"/>
|
||||
</controls:Badge>
|
||||
<controls:Badge Value="100" BadgeMargin="0,-14,-20,0" Height="30" Margin="32,0,0,0" Style="{StaticResource BadgeDanger}">
|
||||
<Button Content="{x:Static langs:Lang.Comment}"/>
|
||||
</controls:Badge>
|
||||
<controls:Badge IsDot="True" Height="30" Margin="32,0,0,0" Style="{StaticResource BadgeDanger}">
|
||||
<controls:Badge Status="Dot" Height="30" Margin="32,0,0,0" Style="{StaticResource BadgeDanger}">
|
||||
<Button Content="{x:Static langs:Lang.Reply}"/>
|
||||
</controls:Badge>
|
||||
<controls:Badge Status="Processing" Height="30" Margin="32,0,0,0" Style="{StaticResource BadgeDanger}">
|
||||
<Button Content="{x:Static langs:Lang.Reply}" />
|
||||
</controls:Badge>
|
||||
</StackPanel>
|
||||
</controls:TransitioningContentControl>
|
||||
</UserControl>
|
||||
@@ -0,0 +1,20 @@
|
||||
using System;
|
||||
using GalaSoft.MvvmLight;
|
||||
using GalaSoft.MvvmLight.CommandWpf;
|
||||
|
||||
namespace HandyControlDemo.ViewModel.Controls
|
||||
{
|
||||
public class BadgeDemoViewModel : ViewModelBase
|
||||
{
|
||||
private int _count = 1;
|
||||
|
||||
public int Count
|
||||
{
|
||||
get => _count;
|
||||
set => Set(ref _count, value);
|
||||
}
|
||||
|
||||
public RelayCommand CountCmd => new Lazy<RelayCommand>(() =>
|
||||
new RelayCommand(() => Count++)).Value;
|
||||
}
|
||||
}
|
||||
@@ -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<SearchBarDemoViewModel>();
|
||||
SimpleIoc.Default.Register<NotifyIconDemoViewModel>();
|
||||
SimpleIoc.Default.Register<InteractiveDialogViewModel>();
|
||||
SimpleIoc.Default.Register<BadgeDemoViewModel>();
|
||||
}
|
||||
|
||||
public static ViewModelLocator Instance => new Lazy<ViewModelLocator>(() =>
|
||||
@@ -67,6 +69,8 @@ namespace HandyControlDemo.ViewModel
|
||||
public NotifyIconDemoViewModel NotifyIconDemo => ServiceLocator.Current.GetInstance<NotifyIconDemoViewModel>();
|
||||
|
||||
public InteractiveDialogViewModel InteractiveDialog => ServiceLocator.Current.GetInstance<InteractiveDialogViewModel>();
|
||||
|
||||
public BadgeDemoViewModel BadgeDemo => ServiceLocator.Current.GetInstance<BadgeDemoViewModel>();
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user