From 7e98de25a39c943c84a6542b3895a8ee3beaa183 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Sat, 22 Dec 2018 16:19:26 +0800 Subject: [PATCH] add FlipClock --- .../Controls/Time/FlipClock/FlipClock.cs | 57 ++++++++++++++++++ .../Controls/Time/FlipClock/FlipNumber.cs | 8 ++- .../Controls/Window/WindowBorderless.cs | 39 ++++++++---- HandyControl/HandyControl.csproj | 3 +- HandyControl/Themes/Styles/FlipClock.xaml | 34 +++++++++++ HandyControl/Themes/Styles/FlipNumber.xaml | 17 ------ HandyControl/Themes/Styles/Style.xaml | 2 +- HandyControl/Themes/Styles/Window.xaml | 22 ++++--- HandyControlDemo/Data/MessageToken.cs | 2 +- HandyControlDemo/Data/MessageToken.tt | 2 +- HandyControlDemo/HandyControlDemo.csproj | 6 +- HandyControlDemo/MainWindow.xaml | 2 +- .../Properties/Langs/Lang.Designer.cs | 6 +- .../Properties/Langs/Lang.en.resx | 6 +- HandyControlDemo/Properties/Langs/Lang.resx | 6 +- .../Controls/FlipClockDemoCtl.xaml | 9 +++ ...moCtl.xaml.cs => FlipClockDemoCtl.xaml.cs} | 4 +- .../Controls/FlipNumberDemoCtl.xaml | 16 ----- .../UserControl/Main/LeftMainContent.xaml | 2 +- .../Window/CustomNonClientAreaWindow.xaml | 2 +- README.md | 8 ++- Resources/FlipClock.gif | Bin 0 -> 127872 bytes 22 files changed, 175 insertions(+), 78 deletions(-) create mode 100644 HandyControl/Controls/Time/FlipClock/FlipClock.cs create mode 100644 HandyControl/Themes/Styles/FlipClock.xaml delete mode 100644 HandyControl/Themes/Styles/FlipNumber.xaml create mode 100644 HandyControlDemo/UserControl/Controls/FlipClockDemoCtl.xaml rename HandyControlDemo/UserControl/Controls/{FlipNumberDemoCtl.xaml.cs => FlipClockDemoCtl.xaml.cs} (59%) delete mode 100644 HandyControlDemo/UserControl/Controls/FlipNumberDemoCtl.xaml create mode 100644 Resources/FlipClock.gif diff --git a/HandyControl/Controls/Time/FlipClock/FlipClock.cs b/HandyControl/Controls/Time/FlipClock/FlipClock.cs new file mode 100644 index 00000000..bd066e7d --- /dev/null +++ b/HandyControl/Controls/Time/FlipClock/FlipClock.cs @@ -0,0 +1,57 @@ +using System; +using System.Collections.Generic; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Threading; + +namespace HandyControl.Controls +{ + public class FlipClock : Control + { + public static readonly DependencyProperty NumberListProperty = DependencyProperty.Register( + "NumberList", typeof(List), typeof(FlipClock), new PropertyMetadata(new List {0, 0, 0, 0, 0, 0})); + + public List NumberList + { + get => (List) GetValue(NumberListProperty); + set => SetValue(NumberListProperty, value); + } + + public static readonly DependencyProperty DisplayTimeProperty = DependencyProperty.Register( + "DisplayTime", typeof(DateTime), typeof(FlipClock), new PropertyMetadata(default(DateTime), OnDisplayTimeChanged)); + + private static void OnDisplayTimeChanged(DependencyObject s, DependencyPropertyChangedEventArgs e) + { + var ctl = (FlipClock) s; + var v = (DateTime) e.NewValue; + + ctl.NumberList = new List + { + v.Hour / 10, + v.Hour % 10, + v.Minute / 10, + v.Minute % 10, + v.Second / 10, + v.Second % 10 + }; + } + + public DateTime DisplayTime + { + get => (DateTime) GetValue(DisplayTimeProperty); + set => SetValue(DisplayTimeProperty, value); + } + + public FlipClock() + { + var dispatcherTimer = new DispatcherTimer + { + Interval = TimeSpan.FromMilliseconds(200) + }; + dispatcherTimer.Tick += DispatcherTimer_Tick; + dispatcherTimer.Start(); + } + + private void DispatcherTimer_Tick(object sender, EventArgs e) => DisplayTime = DateTime.Now; + } +} \ No newline at end of file diff --git a/HandyControl/Controls/Time/FlipClock/FlipNumber.cs b/HandyControl/Controls/Time/FlipClock/FlipNumber.cs index cd699064..9a4cf8e6 100644 --- a/HandyControl/Controls/Time/FlipClock/FlipNumber.cs +++ b/HandyControl/Controls/Time/FlipClock/FlipNumber.cs @@ -1,4 +1,5 @@ using System; +using System.ComponentModel; using System.Windows; using System.Windows.Controls; using System.Windows.Media; @@ -64,6 +65,7 @@ namespace HandyControl.Controls public static readonly DependencyProperty FontSizeProperty = DependencyProperty.Register( "FontSize", typeof(double), typeof(FlipNumber), new PropertyMetadata(70.0)); + [TypeConverter(typeof(FontSizeConverter))] public double FontSize { get => (double)GetValue(FontSizeProperty); @@ -96,7 +98,7 @@ namespace HandyControl.Controls Axis = new Vector3D(1, 0, 0) }; - _animation = new DoubleAnimation(0, 180, new Duration(TimeSpan.FromSeconds(1))) + _animation = new DoubleAnimation(0, 180, new Duration(TimeSpan.FromSeconds(0.8))) { FillBehavior = FillBehavior.Stop }; @@ -153,8 +155,12 @@ namespace HandyControl.Controls Children.Add(_content); } + private bool CheckNull() => _page1TextDown != null && _page2TextUp != null && _page2TextDown != null && _page3TextUp != null; + private void OnNumberChanged() { + if (!CheckNull()) return; + InitNewNumber(); if (_isAnimating) diff --git a/HandyControl/Controls/Window/WindowBorderless.cs b/HandyControl/Controls/Window/WindowBorderless.cs index 3b427c3d..496a0db8 100644 --- a/HandyControl/Controls/Window/WindowBorderless.cs +++ b/HandyControl/Controls/Window/WindowBorderless.cs @@ -8,7 +8,6 @@ using System.Windows.Shell; using HandyControl.Data; using HandyControl.Tools; -// ReSharper disable once CheckNamespace namespace HandyControl.Controls { /// @@ -21,8 +20,8 @@ namespace HandyControl.Controls public static readonly DependencyProperty NonClientAreaContentProperty = DependencyProperty.Register( "NonClientAreaContent", typeof(object), typeof(WindowBorderless), new PropertyMetadata(default(object))); - public static readonly DependencyProperty CloseButtonHoverBrushProperty = DependencyProperty.Register( - "CloseButtonHoverBrush", typeof(Brush), typeof(WindowBorderless), + public static readonly DependencyProperty CloseButtonHoverBackgroundProperty = DependencyProperty.Register( + "CloseButtonHoverBackground", typeof(Brush), typeof(WindowBorderless), new PropertyMetadata(default(Brush))); public static readonly DependencyProperty CloseButtonHoverForegroundProperty = @@ -30,16 +29,22 @@ namespace HandyControl.Controls "CloseButtonHoverForeground", typeof(Brush), typeof(WindowBorderless), new PropertyMetadata(default(Brush))); + public static readonly DependencyProperty CloseButtonBackgroundProperty = DependencyProperty.Register( + "CloseButtonBackground", typeof(Brush), typeof(WindowBorderless), new PropertyMetadata(Brushes.Transparent)); + public static readonly DependencyProperty CloseButtonForegroundProperty = DependencyProperty.Register( "CloseButtonForeground", typeof(Brush), typeof(WindowBorderless), new PropertyMetadata(Brushes.White)); + public static readonly DependencyProperty OtherButtonBackgroundProperty = DependencyProperty.Register( + "OtherButtonBackground", typeof(Brush), typeof(WindowBorderless), new PropertyMetadata(Brushes.Transparent)); + public static readonly DependencyProperty OtherButtonForegroundProperty = DependencyProperty.Register( "OtherButtonForeground", typeof(Brush), typeof(WindowBorderless), new PropertyMetadata(Brushes.White)); - public static readonly DependencyProperty OtherButtonHoverBrushProperty = DependencyProperty.Register( - "OtherButtonHoverBrush", typeof(Brush), typeof(WindowBorderless), + public static readonly DependencyProperty OtherButtonHoverBackgroundProperty = DependencyProperty.Register( + "OtherButtonHoverBackground", typeof(Brush), typeof(WindowBorderless), new PropertyMetadata(default(Brush))); public static readonly DependencyProperty OtherButtonHoverForegroundProperty = @@ -144,12 +149,24 @@ namespace HandyControl.Controls Dispatcher.BeginInvoke(new Action(() => { SizeToContent = SizeToContent.WidthAndHeight; })); } + public Brush CloseButtonBackground + { + get => (Brush)GetValue(CloseButtonBackgroundProperty); + set => SetValue(CloseButtonBackgroundProperty, value); + } + public Brush CloseButtonForeground { get => (Brush)GetValue(CloseButtonForegroundProperty); set => SetValue(CloseButtonForegroundProperty, value); } + public Brush OtherButtonBackground + { + get => (Brush)GetValue(OtherButtonBackgroundProperty); + set => SetValue(OtherButtonBackgroundProperty, value); + } + public Brush OtherButtonForeground { get => (Brush)GetValue(OtherButtonForegroundProperty); @@ -189,10 +206,10 @@ namespace HandyControl.Controls set => SetValue(NonClientAreaContentProperty, value); } - public Brush CloseButtonHoverBrush + public Brush CloseButtonHoverBackground { - get => (Brush)GetValue(CloseButtonHoverBrushProperty); - set => SetValue(CloseButtonHoverBrushProperty, value); + get => (Brush)GetValue(CloseButtonHoverBackgroundProperty); + set => SetValue(CloseButtonHoverBackgroundProperty, value); } public Brush CloseButtonHoverForeground @@ -201,10 +218,10 @@ namespace HandyControl.Controls set => SetValue(CloseButtonHoverForegroundProperty, value); } - public Brush OtherButtonHoverBrush + public Brush OtherButtonHoverBackground { - get => (Brush)GetValue(OtherButtonHoverBrushProperty); - set => SetValue(OtherButtonHoverBrushProperty, value); + get => (Brush)GetValue(OtherButtonHoverBackgroundProperty); + set => SetValue(OtherButtonHoverBackgroundProperty, value); } public Brush OtherButtonHoverForeground diff --git a/HandyControl/HandyControl.csproj b/HandyControl/HandyControl.csproj index cd066d18..a1439ca2 100644 --- a/HandyControl/HandyControl.csproj +++ b/HandyControl/HandyControl.csproj @@ -94,6 +94,7 @@ + @@ -316,7 +317,7 @@ Designer MSBuild:Compile - + Designer MSBuild:Compile diff --git a/HandyControl/Themes/Styles/FlipClock.xaml b/HandyControl/Themes/Styles/FlipClock.xaml new file mode 100644 index 00000000..0acfa6d0 --- /dev/null +++ b/HandyControl/Themes/Styles/FlipClock.xaml @@ -0,0 +1,34 @@ + + + + + + + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/FlipNumber.xaml b/HandyControl/Themes/Styles/FlipNumber.xaml deleted file mode 100644 index e9b64e82..00000000 --- a/HandyControl/Themes/Styles/FlipNumber.xaml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - \ No newline at end of file diff --git a/HandyControl/Themes/Styles/Style.xaml b/HandyControl/Themes/Styles/Style.xaml index 557c4b57..67c82899 100644 --- a/HandyControl/Themes/Styles/Style.xaml +++ b/HandyControl/Themes/Styles/Style.xaml @@ -47,7 +47,7 @@ - + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/Window.xaml b/HandyControl/Themes/Styles/Window.xaml index 11b46fa8..5c6cb6dc 100644 --- a/HandyControl/Themes/Styles/Window.xaml +++ b/HandyControl/Themes/Styles/Window.xaml @@ -24,10 +24,12 @@ - + - + + + @@ -43,10 +45,10 @@ -