Skip to content

Commit

Permalink
update to v1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
NaBian committed Sep 4, 2018
1 parent c402f42 commit 4afd109
Show file tree
Hide file tree
Showing 90 changed files with 2,992 additions and 1,652 deletions.
1 change: 1 addition & 0 deletions .gitignore
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
Expand Down
14 changes: 14 additions & 0 deletions ChangeLog.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,17 @@
2018.09.04 Version 1.2.0
* new controls
- add Growl
- add AnimationPath
- add TransitioningContentControl

* new style
- add ProgressBar
- add TreeView

* other
- update HandyControlDemo UI
- the ScrollViewer will auto hidden

2018.08.31 Version 1.1.2
* new controls
- add CompareSlider
Expand Down
188 changes: 188 additions & 0 deletions HandyControl/Controls/AnimationPath.cs
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();
}
}
}
35 changes: 35 additions & 0 deletions HandyControl/Controls/Attach/BackgroundSwitchElement.cs
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);
}
}
}
21 changes: 21 additions & 0 deletions HandyControl/Controls/Attach/BorderElement.cs
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);
}
}
}
18 changes: 0 additions & 18 deletions HandyControl/Controls/ColorPicker.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -75,24 +75,6 @@
<TextBlock Foreground="{StaticResource ThirdlyTextBrush}" Margin="0,6,0,0" FontSize="10" Text="A" HorizontalAlignment="Center"></TextBlock>
</StackPanel>
</UniformGrid>
<!--<UniformGrid Visibility="{Binding ShowList[2],ElementName=UserControlMain,Converter={StaticResource Boolean2VisibilityConverter}}" Rows="1" Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="2" Margin="-2,14,-2,0" VerticalAlignment="Top">
<StackPanel Margin="2,0">
<controls:InfoTextBox TextPadding="0" Text="{Binding ColorInfoList[5],ElementName=UserControlMain}" FontSize="10" ShowSmallCornerRadius="True" MaxLength="3" ShowClearButton="False" HorizontalTextAlignment="Center" IsNeedly="False" Height="24" ></controls:InfoTextBox>
<TextBlock Foreground="{StaticResource ThirdlyTextBrush}" Margin="0,6,0,0" FontSize="10" Text="H" HorizontalAlignment="Center"></TextBlock>
</StackPanel>
<StackPanel Margin="2,0">
<controls:InfoTextBox TextPadding="0" Text="{Binding ColorInfoList[6],ElementName=UserControlMain}" FontSize="10" ShowSmallCornerRadius="True" MaxLength="3" ShowClearButton="False" HorizontalTextAlignment="Center" IsNeedly="False" Height="24" ></controls:InfoTextBox>
<TextBlock Foreground="{StaticResource ThirdlyTextBrush}" Margin="0,6,0,0" FontSize="10" Text="S" HorizontalAlignment="Center"></TextBlock>
</StackPanel>
<StackPanel Margin="2,0">
<controls:InfoTextBox TextPadding="0" Text="{Binding ColorInfoList[7],ElementName=UserControlMain}" FontSize="10" ShowSmallCornerRadius="True" MaxLength="3" ShowClearButton="False" HorizontalTextAlignment="Center" IsNeedly="False" Height="24" ></controls:InfoTextBox>
<TextBlock Foreground="{StaticResource ThirdlyTextBrush}" Margin="0,6,0,0" FontSize="10" Text="L" HorizontalAlignment="Center"></TextBlock>
</StackPanel>
<StackPanel Margin="2,0">
<controls:InfoTextBox TextPadding="0" Text="{Binding ColorInfoList[8],ElementName=UserControlMain}" FontSize="10" ShowSmallCornerRadius="True" MaxLength="3" ShowClearButton="False" HorizontalTextAlignment="Center" IsNeedly="False" Height="24" ></controls:InfoTextBox>
<TextBlock Foreground="{StaticResource ThirdlyTextBrush}" Margin="0,6,0,0" FontSize="10" Text="A" HorizontalAlignment="Center"></TextBlock>
</StackPanel>
</UniformGrid>-->
<Button Click="ButtonSwitch_OnClick" Padding="6" FontSize="8" BorderThickness="0" Foreground="#323534" HorizontalAlignment="Right" Height="24" Width="20" Grid.Column="2" Grid.Row="1">
<Button.Content>
<Path Fill="#323534" Style="{StaticResource UpDownPathStyle}"></Path>
Expand Down
60 changes: 60 additions & 0 deletions HandyControl/Controls/Growl.xaml
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>
Loading

0 comments on commit 4afd109

Please sign in to comment.