From 1198fd1f2de0db6bfef0f7fb24aa0a10b9547f7f Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Tue, 27 Aug 2019 22:42:41 +0800 Subject: [PATCH] improved RunningBlock --- .../Controls/RunningBlockDemoCtl.xaml | 2 + .../Controls/Other/RunningBlock.cs | 44 ++++++++++++++++--- .../Styles/Base/RunningBlockBaseStyle.xaml | 7 ++- 3 files changed, 46 insertions(+), 7 deletions(-) diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/RunningBlockDemoCtl.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/RunningBlockDemoCtl.xaml index cbfbf22f..31b01b4b 100644 --- a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/RunningBlockDemoCtl.xaml +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/RunningBlockDemoCtl.xaml @@ -8,6 +8,8 @@ + + diff --git a/src/Shared/HandyControl_Shared/Controls/Other/RunningBlock.cs b/src/Shared/HandyControl_Shared/Controls/Other/RunningBlock.cs index 7ce0bbc6..6470b79f 100644 --- a/src/Shared/HandyControl_Shared/Controls/Other/RunningBlock.cs +++ b/src/Shared/HandyControl_Shared/Controls/Other/RunningBlock.cs @@ -29,6 +29,15 @@ namespace HandyControl.Controls _elementPanel = GetTemplateChild(ElementPanel) as Panel; } + public static readonly DependencyProperty OrientationProperty = DependencyProperty.Register( + "Orientation", typeof(Orientation), typeof(RunningBlock), new FrameworkPropertyMetadata(default(Orientation), FrameworkPropertyMetadataOptions.AffectsRender)); + + public Orientation Orientation + { + get => (Orientation) GetValue(OrientationProperty); + set => SetValue(OrientationProperty, value); + } + public static readonly DependencyProperty DurationProperty = DependencyProperty.Register( "Duration", typeof(Duration), typeof(RunningBlock), new FrameworkPropertyMetadata(new Duration(TimeSpan.FromSeconds(5)), FrameworkPropertyMetadataOptions.AffectsRender)); @@ -59,6 +68,15 @@ namespace HandyControl.Controls set => SetValue(IsRunningProperty, value); } + public static readonly DependencyProperty AutoReverseProperty = DependencyProperty.Register( + "AutoReverse", typeof(bool), typeof(RunningBlock), new FrameworkPropertyMetadata(ValueBoxes.FalseBox, FrameworkPropertyMetadataOptions.AffectsRender)); + + public bool AutoReverse + { + get => (bool) GetValue(AutoReverseProperty); + set => SetValue(AutoReverseProperty, value); + } + private void UpdateContent() { if (_elementContent == null || _elementPanel == null) return; @@ -70,14 +88,28 @@ namespace HandyControl.Controls _elementPanel.Width = _elementPanel.DesiredSize.Width; _elementPanel.Height = _elementPanel.DesiredSize.Height; - var animation = new DoubleAnimation(-_elementPanel.Width, ActualWidth, Duration) + DoubleAnimation animation; + if (Orientation == Orientation.Horizontal) { - RepeatBehavior = RepeatBehavior.Forever - }; - Storyboard.SetTarget(animation, _elementContent); - Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)")); - _storyboard.Children.Add(animation); + animation = new DoubleAnimation(-_elementPanel.Width, ActualWidth, Duration) + { + RepeatBehavior = RepeatBehavior.Forever, + AutoReverse = AutoReverse + }; + Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.X)")); + } + else + { + animation = new DoubleAnimation(-_elementPanel.Height, ActualHeight, Duration) + { + RepeatBehavior = RepeatBehavior.Forever, + AutoReverse = AutoReverse + }; + Storyboard.SetTargetProperty(animation, new PropertyPath("(UIElement.RenderTransform).(TransformGroup.Children)[0].(TranslateTransform.Y)")); + } + Storyboard.SetTarget(animation, _elementContent); + _storyboard.Children.Add(animation); _storyboard.Begin(); } diff --git a/src/Shared/HandyControl_Shared/Themes/Styles/Base/RunningBlockBaseStyle.xaml b/src/Shared/HandyControl_Shared/Themes/Styles/Base/RunningBlockBaseStyle.xaml index 25343f76..ba1ee285 100644 --- a/src/Shared/HandyControl_Shared/Themes/Styles/Base/RunningBlockBaseStyle.xaml +++ b/src/Shared/HandyControl_Shared/Themes/Styles/Base/RunningBlockBaseStyle.xaml @@ -20,7 +20,7 @@ - + @@ -29,6 +29,11 @@ + + + + + \ No newline at end of file