-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
90 changed files
with
2,992 additions
and
1,652 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/.vs | ||
/packages | ||
/HandyControl/bin/Debug | ||
/HandyControl/obj/Debug | ||
/HandyControl/bin/Release | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,188 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Windows; | ||
using System.Windows.Media; | ||
using System.Windows.Media.Animation; | ||
using System.Windows.Shapes; | ||
|
||
namespace HandyControl.Controls | ||
{ | ||
public class AnimationPath : Shape | ||
{ | ||
private bool _isLoaded; | ||
|
||
/// <summary> | ||
/// 故事版 | ||
/// </summary> | ||
private Storyboard _storyboard; | ||
|
||
/// <summary> | ||
/// 路径 | ||
/// </summary> | ||
public static readonly DependencyProperty DataProperty = DependencyProperty.Register(nameof(Data), | ||
typeof(Geometry), typeof(AnimationPath), new FrameworkPropertyMetadata(null, | ||
OnPropertiesChanged)); | ||
|
||
private static void OnPropertiesChanged(DependencyObject d, DependencyPropertyChangedEventArgs e) | ||
{ | ||
if (d is AnimationPath path) | ||
{ | ||
path.UpdatePath(); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// 路径 | ||
/// </summary> | ||
public Geometry Data | ||
{ | ||
get => (Geometry)GetValue(DataProperty); | ||
set => SetValue(DataProperty, value); | ||
} | ||
|
||
protected override Geometry DefiningGeometry => Data ?? Geometry.Empty; | ||
|
||
/// <summary> | ||
/// 路径长度 | ||
/// </summary> | ||
public static readonly DependencyProperty PathLengthProperty = DependencyProperty.Register( | ||
"PathLength", typeof(double), typeof(AnimationPath), new FrameworkPropertyMetadata(default(double), | ||
OnPropertiesChanged)); | ||
|
||
/// <summary> | ||
/// 路径长度 | ||
/// </summary> | ||
public double PathLength | ||
{ | ||
get => (double)GetValue(PathLengthProperty); | ||
set => SetValue(PathLengthProperty, value); | ||
} | ||
|
||
/// <summary> | ||
/// 动画间隔时间 | ||
/// </summary> | ||
public static readonly DependencyProperty DurationProperty = DependencyProperty.Register( | ||
"Duration", typeof(Duration), typeof(AnimationPath), new FrameworkPropertyMetadata(new Duration(TimeSpan.FromSeconds(2)), | ||
OnPropertiesChanged)); | ||
|
||
/// <summary> | ||
/// 动画间隔时间 | ||
/// </summary> | ||
public Duration Duration | ||
{ | ||
get => (Duration)GetValue(DurationProperty); | ||
set => SetValue(DurationProperty, value); | ||
} | ||
|
||
public static readonly DependencyProperty IsPlayingProperty = DependencyProperty.Register( | ||
"IsPlaying", typeof(bool), typeof(AnimationPath), new FrameworkPropertyMetadata(true, (o, args) => | ||
{ | ||
var ctl = (AnimationPath)o; | ||
var v = (bool)args.NewValue; | ||
if (v) | ||
{ | ||
ctl.UpdatePath(); | ||
} | ||
else | ||
{ | ||
ctl._storyboard?.Pause(); | ||
} | ||
})); | ||
|
||
/// <summary> | ||
/// 是否正在播放动画 | ||
/// </summary> | ||
public bool IsPlaying | ||
{ | ||
get => (bool)GetValue(IsPlayingProperty); | ||
set => SetValue(IsPlayingProperty, value); | ||
} | ||
|
||
public static readonly DependencyProperty RepeatBehaviorProperty = DependencyProperty.Register( | ||
"RepeatBehavior", typeof(RepeatBehavior), typeof(AnimationPath), new PropertyMetadata(RepeatBehavior.Forever)); | ||
|
||
/// <summary> | ||
/// 动画重复行为 | ||
/// </summary> | ||
public RepeatBehavior RepeatBehavior | ||
{ | ||
get => (RepeatBehavior)GetValue(RepeatBehaviorProperty); | ||
set => SetValue(RepeatBehaviorProperty, value); | ||
} | ||
|
||
static AnimationPath() | ||
{ | ||
StretchProperty.AddOwner(typeof(AnimationPath), new FrameworkPropertyMetadata(Stretch.Uniform, | ||
OnPropertiesChanged)); | ||
|
||
StrokeThicknessProperty.AddOwner(typeof(AnimationPath), new FrameworkPropertyMetadata(1.0, | ||
OnPropertiesChanged)); | ||
} | ||
|
||
public AnimationPath() | ||
{ | ||
Loaded += (s, e) => | ||
{ | ||
if (_isLoaded) return; | ||
UpdatePath(); | ||
_isLoaded = true; | ||
}; | ||
} | ||
|
||
/// <summary> | ||
/// 动画完成事件 | ||
/// </summary> | ||
public static readonly RoutedEvent CompletedEvent = | ||
EventManager.RegisterRoutedEvent("Completed", RoutingStrategy.Bubble, | ||
typeof(EventHandler), typeof(AnimationPath)); | ||
|
||
/// <summary> | ||
/// 动画完成事件 | ||
/// </summary> | ||
public event EventHandler Completed | ||
{ | ||
add => AddHandler(CompletedEvent, value); | ||
remove => RemoveHandler(CompletedEvent, value); | ||
} | ||
|
||
private void UpdatePath() | ||
{ | ||
if (!Duration.HasTimeSpan || !IsPlaying) return; | ||
StrokeDashOffset = PathLength; | ||
StrokeDashArray = new DoubleCollection(new List<double> | ||
{ | ||
PathLength, | ||
PathLength | ||
}); | ||
|
||
//定义动画 | ||
_storyboard = new Storyboard | ||
{ | ||
RepeatBehavior = RepeatBehavior | ||
}; | ||
_storyboard.Completed += (s, e) => RaiseEvent(new RoutedEventArgs(CompletedEvent)); | ||
|
||
var frames = new DoubleAnimationUsingKeyFrames(); | ||
//开始位置 | ||
var frame0 = new LinearDoubleKeyFrame | ||
{ | ||
Value = PathLength, | ||
KeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero) | ||
}; | ||
//结束位置 | ||
var frame1 = new LinearDoubleKeyFrame | ||
{ | ||
Value = -PathLength, | ||
KeyTime = KeyTime.FromTimeSpan(Duration.TimeSpan) | ||
}; | ||
frames.KeyFrames.Add(frame0); | ||
frames.KeyFrames.Add(frame1); | ||
|
||
Storyboard.SetTarget(frames, this); | ||
Storyboard.SetTargetProperty(frames, new PropertyPath(StrokeDashOffsetProperty)); | ||
_storyboard.Children.Add(frames); | ||
|
||
_storyboard.Begin(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using System.Windows; | ||
using System.Windows.Media; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace HandyControl.Controls | ||
{ | ||
public class BackgroundSwitchElement : DependencyObject | ||
{ | ||
public static readonly DependencyProperty MouseHoverBackgroundProperty = DependencyProperty.RegisterAttached( | ||
"MouseHoverBackground", typeof(Brush), typeof(BackgroundSwitchElement), new PropertyMetadata(Brushes.Transparent)); | ||
|
||
public static void SetMouseHoverBackground(DependencyObject element, Brush value) | ||
{ | ||
element.SetValue(MouseHoverBackgroundProperty, value); | ||
} | ||
|
||
public static Brush GetMouseHoverBackground(DependencyObject element) | ||
{ | ||
return (Brush)element.GetValue(MouseHoverBackgroundProperty); | ||
} | ||
|
||
public static readonly DependencyProperty MouseDownBackgroundProperty = DependencyProperty.RegisterAttached( | ||
"MouseDownBackground", typeof(Brush), typeof(BackgroundSwitchElement), new PropertyMetadata(Brushes.Transparent)); | ||
|
||
public static void SetMouseDownBackground(DependencyObject element, Brush value) | ||
{ | ||
element.SetValue(MouseDownBackgroundProperty, value); | ||
} | ||
|
||
public static Brush GetMouseDownBackground(DependencyObject element) | ||
{ | ||
return (Brush)element.GetValue(MouseDownBackgroundProperty); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
using System.Windows; | ||
|
||
// ReSharper disable once CheckNamespace | ||
namespace HandyControl.Controls | ||
{ | ||
public class BorderElement : DependencyObject | ||
{ | ||
public static readonly DependencyProperty CornerRadiusProperty = DependencyProperty.RegisterAttached( | ||
"CornerRadius", typeof(CornerRadius), typeof(BorderElement), new PropertyMetadata(default(CornerRadius))); | ||
|
||
public static void SetCornerRadius(DependencyObject element, CornerRadius value) | ||
{ | ||
element.SetValue(CornerRadiusProperty, value); | ||
} | ||
|
||
public static CornerRadius GetCornerRadius(DependencyObject element) | ||
{ | ||
return (CornerRadius) element.GetValue(CornerRadiusProperty); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<UserControl x:Class="HandyControl.Controls.Growl" | ||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" | ||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" | ||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" | ||
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" | ||
mc:Ignorable="d" | ||
MinHeight="60" | ||
Name="UserControlThis" | ||
Width="320" | ||
Margin="0,0,0,10" | ||
MaxWidth="320"> | ||
<UserControl.Triggers> | ||
<EventTrigger RoutedEvent="UserControl.MouseEnter"> | ||
<BeginStoryboard> | ||
<Storyboard> | ||
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Button.Visibility)" Storyboard.TargetName="ButtonClose"> | ||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}"/> | ||
</ObjectAnimationUsingKeyFrames> | ||
</Storyboard> | ||
</BeginStoryboard> | ||
</EventTrigger> | ||
<EventTrigger RoutedEvent="UserControl.MouseLeave"> | ||
<BeginStoryboard> | ||
<Storyboard> | ||
<ObjectAnimationUsingKeyFrames Storyboard.TargetProperty="(Button.Visibility)" Storyboard.TargetName="ButtonClose"> | ||
<DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Collapsed}"/> | ||
</ObjectAnimationUsingKeyFrames> | ||
</Storyboard> | ||
</BeginStoryboard> | ||
</EventTrigger> | ||
</UserControl.Triggers> | ||
<Grid Name="GridMain" RenderTransformOrigin="0.5,0.5"> | ||
<Grid.ColumnDefinitions> | ||
<ColumnDefinition Width="50"/> | ||
<ColumnDefinition/> | ||
<ColumnDefinition Width="Auto"/> | ||
</Grid.ColumnDefinitions> | ||
<Grid.RowDefinitions> | ||
<RowDefinition/> | ||
<RowDefinition Height="Auto"/> | ||
</Grid.RowDefinitions> | ||
<Border Grid.ColumnSpan="3" Grid.RowSpan="2" Effect="{StaticResource EffectShadow2}" Background="#E5DEDEDE" CornerRadius="8" Width="320"></Border> | ||
<Path Grid.Row="0" Grid.Column="0" VerticalAlignment="Top" Margin="0,15,0,0" Width="30" Height="30" Data="{Binding Icon,ElementName=UserControlThis}" Stretch="Uniform" Fill="{Binding IconBrush,ElementName=UserControlThis}"></Path> | ||
<StackPanel Grid.Row="0" Grid.Column="1" Margin="0,12,10,10"> | ||
<TextBlock Text="{Binding Message,ElementName=UserControlThis}" Style="{StaticResource TextBlockDefault}" HorizontalAlignment="Left" TextWrapping="Wrap"></TextBlock> | ||
<TextBlock Text="{Binding Time,ElementName=UserControlThis,StringFormat=yyyy/MM/dd HH:mm:ss}" Style="{StaticResource TextBlockDefault}" Foreground="{StaticResource SecondaryTextBrush}" HorizontalAlignment="Left" Margin="0,4,0,0"></TextBlock> | ||
</StackPanel> | ||
<Button Grid.Row="0" Visibility="Collapsed" Margin="11,0" Name="ButtonClose" Click="ButtonClose_OnClick" Grid.Column="2" Background="Transparent" Style="{StaticResource ButtonOpacityStyle}" VerticalAlignment="Center" HorizontalAlignment="Center" Width="18" Height="18"> | ||
<Path Data="{StaticResource ErrorGeometry}" Stretch="Uniform" Fill="{StaticResource SecondaryTextBrush}"></Path> | ||
</Button> | ||
<StackPanel Name="PanelMore" IsEnabled="False" Visibility="Collapsed" Orientation="Horizontal" Grid.Row="1" Grid.ColumnSpan="3" Height="28" Grid.Column="0"> | ||
<Button Click="ButtonCancel_OnClick" Style="{StaticResource ButtonOpacityStyle}" Width="160"> | ||
<TextBlock Text="取消" HorizontalAlignment="Center" Foreground="{StaticResource DangerBrush}"></TextBlock> | ||
</Button> | ||
<Button Click="ButtonOk_OnClick" Style="{StaticResource ButtonOpacityStyle}" Width="160"> | ||
<TextBlock Text="确定" HorizontalAlignment="Center" Foreground="{StaticResource PrimaryBrush}"></TextBlock> | ||
</Button> | ||
</StackPanel> | ||
</Grid> | ||
</UserControl> |
Oops, something went wrong.