update pr/59

This commit is contained in:
NaBian 2019-04-04 23:51:42 +08:00
parent 0fb520bf8d
commit ada85bb59d
13 changed files with 230 additions and 236 deletions

View File

@ -1,37 +1,31 @@
using System.Windows;
using System;
using System.Windows;
using System.Windows.Controls;
using HandyControl.Data;
namespace HandyControl.Controls
{
public enum BadgeStatus { Normal, Dot, Processing }
/// <summary>
/// 标记
/// </summary>
public class Badge : ContentControl
{
public static readonly RoutedEvent BadgeChangedEvent = EventManager.RegisterRoutedEvent(
"BadgeChanged", RoutingStrategy.Direct, typeof(RoutedEventHandler), typeof(Badge));
public static readonly RoutedEvent ValueChangedEvent =
EventManager.RegisterRoutedEvent("ValueChanged", RoutingStrategy.Bubble,
typeof(EventHandler<FunctionEventArgs<int>>), typeof(Badge));
public event RoutedEventHandler BadgeChanged
public event EventHandler<FunctionEventArgs<int>> ValueChanged
{
add => AddHandler(BadgeChangedEvent, value);
remove => RemoveHandler(BadgeChangedEvent, value);
add => AddHandler(ValueChangedEvent, value);
remove => RemoveHandler(ValueChangedEvent, value);
}
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
"Text", typeof(string), typeof(Badge), new PropertyMetadata(default(string), (o, args) =>
{
var ctl = (Badge)o;
if (ctl.IsInitialized)
ctl.RaiseEvent(new RoutedEventArgs(BadgeChangedEvent, ctl));
}));
"Text", typeof(string), typeof(Badge), new PropertyMetadata(default(string)));
public string Text
{
get => (string)GetValue(TextProperty);
get => (string) GetValue(TextProperty);
set => SetValue(TextProperty, value);
}
@ -43,6 +37,13 @@ namespace HandyControl.Controls
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

View File

@ -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
{

View File

@ -0,0 +1,9 @@
namespace HandyControl.Data
{
public enum BadgeStatus
{
Text,
Dot,
Processing
}
}

View File

@ -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" />

View File

@ -13,28 +13,15 @@
<Border.RenderTransform>
<ScaleTransform />
</Border.RenderTransform>
<ContentPresenter ContentSource="Text" Margin="{TemplateBinding Padding}" />
</Border>
</controls:SimplePanel>
<ControlTemplate.Triggers>
<EventTrigger RoutedEvent="controls:Badge.BadgeChanged">
<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}" />
<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>

View File

@ -364,7 +364,7 @@
<Compile Include="ViewModel\Basic\ChatBoxViewModel.cs" />
<Compile Include="ViewModel\Basic\InteractiveDialogViewModel.cs" />
<Compile Include="ViewModel\Common\ComboBoxDemoViewModel.cs" />
<Compile Include="ViewModel\Controls\BadgeDemoCtlViewModel.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" />

File diff suppressed because it is too large Load Diff

View File

@ -561,7 +561,7 @@
<data name="PleaseInput" xml:space="preserve">
<value>Please input...</value>
</data>
<data name="Count" xml:space="preserve">
<value>Count</value>
<data name="Click2Count" xml:space="preserve">
<value>Click to count</value>
</data>
</root>

View File

@ -561,7 +561,7 @@
<data name="PleaseInput" xml:space="preserve">
<value>请输入...</value>
</data>
<data name="Count" xml:space="preserve">
<data name="Click2Count" xml:space="preserve">
<value>点击计数</value>
</data>
</root>

View File

@ -4,7 +4,7 @@
xmlns:controls="clr-namespace:HandyControl.Controls;assembly=HandyControl"
xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"
Background="{DynamicResource RegionBrush}"
DataContext="{Binding Path=BadgeDemoCtl, Source={StaticResource Locator}}">
DataContext="{Binding BadgeDemo, Source={StaticResource Locator}}">
<controls:TransitioningContentControl>
<StackPanel Margin="32" Orientation="Horizontal">
<controls:Badge Text="New" BadgeMargin="0,-14,-20,0" Height="30">
@ -13,8 +13,8 @@
<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="{Binding Count}" Height="30" Margin="32,0,0,0" Style="{StaticResource BadgePrimary}">
<Button Content="{x:Static langs:Lang.Count}" Command="{Binding CountCommand}"/>
<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}"/>

View File

@ -1,25 +0,0 @@
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++);
}
}
}

View File

@ -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;
}
}

View File

@ -32,7 +32,7 @@ namespace HandyControlDemo.ViewModel
SimpleIoc.Default.Register<SearchBarDemoViewModel>();
SimpleIoc.Default.Register<NotifyIconDemoViewModel>();
SimpleIoc.Default.Register<InteractiveDialogViewModel>();
SimpleIoc.Default.Register<BadgeDemoCtlViewModel>();
SimpleIoc.Default.Register<BadgeDemoViewModel>();
}
public static ViewModelLocator Instance => new Lazy<ViewModelLocator>(() =>
@ -70,7 +70,7 @@ namespace HandyControlDemo.ViewModel
public InteractiveDialogViewModel InteractiveDialog => ServiceLocator.Current.GetInstance<InteractiveDialogViewModel>();
public BadgeDemoCtlViewModel BadgeDemoCtl => ServiceLocator.Current.GetInstance<BadgeDemoCtlViewModel>();
public BadgeDemoViewModel BadgeDemo => ServiceLocator.Current.GetInstance<BadgeDemoViewModel>();
#endregion
}
}