diff --git a/README.md b/README.md index 5c454e93..aeeee73f 100644 --- a/README.md +++ b/README.md @@ -63,6 +63,10 @@ Step 4:enjoy coding ## Latest examples +### RunningBlock + +![RunningBlock](https://raw.githubusercontent.com/NaBian/HandyControl/master/Resources/RunningBlock.gif) + ### ImageBlock ![ImageBlock](https://raw.githubusercontent.com/NaBian/HandyControl/master/Resources/ImageBlock.gif) diff --git a/Resources/RunningBlock.gif b/Resources/RunningBlock.gif new file mode 100644 index 00000000..be67ee47 Binary files /dev/null and b/Resources/RunningBlock.gif differ diff --git a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/RunningBlockDemoCtl.xaml b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/RunningBlockDemoCtl.xaml index ae97d2a2..cbfbf22f 100644 --- a/src/Shared/HandyControlDemo_Shared/UserControl/Controls/RunningBlockDemoCtl.xaml +++ b/src/Shared/HandyControlDemo_Shared/UserControl/Controls/RunningBlockDemoCtl.xaml @@ -4,22 +4,24 @@ xmlns:hc="https://handyorg.github.io/handycontrol" Background="{DynamicResource RegionBrush}" xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"> - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + diff --git a/src/Shared/HandyControl_Shared/Controls/Image/GifImage.cs b/src/Shared/HandyControl_Shared/Controls/Image/GifImage.cs index e352119a..38ac8392 100644 --- a/src/Shared/HandyControl_Shared/Controls/Image/GifImage.cs +++ b/src/Shared/HandyControl_Shared/Controls/Image/GifImage.cs @@ -83,6 +83,8 @@ namespace HandyControl.Controls StartAnimate(); } }; + + Unloaded += (s, e) => Dispose(); } public GifImage(string filename) diff --git a/src/Shared/HandyControl_Shared/Controls/Other/RunningBlock.cs b/src/Shared/HandyControl_Shared/Controls/Other/RunningBlock.cs index b02dd021..ce1b96c1 100644 --- a/src/Shared/HandyControl_Shared/Controls/Other/RunningBlock.cs +++ b/src/Shared/HandyControl_Shared/Controls/Other/RunningBlock.cs @@ -7,28 +7,26 @@ using HandyControl.Data; namespace HandyControl.Controls { - [TemplatePart(Name = ElementContent, Type = typeof(UIElement))] + [TemplatePart(Name = ElementContent, Type = typeof(FrameworkElement))] + [TemplatePart(Name = ElementPanel, Type = typeof(Panel))] public class RunningBlock : ContentControl { private const string ElementContent = "PART_ContentElement"; + private const string ElementPanel = "PART_Panel"; + protected Storyboard _storyboard; - private UIElement _elementContent; + private FrameworkElement _elementContent; + + private FrameworkElement _elementPanel; + public override void OnApplyTemplate() { base.OnApplyTemplate(); - _elementContent = GetTemplateChild(ElementContent) as UIElement; - } - - 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); + _elementContent = GetTemplateChild(ElementContent) as FrameworkElement; + _elementPanel = GetTemplateChild(ElementPanel) as Panel; } public static readonly DependencyProperty DurationProperty = DependencyProperty.Register( @@ -63,11 +61,16 @@ namespace HandyControl.Controls private void UpdateContent() { - if (_elementContent == null) return; + if (_elementContent == null || _elementPanel == null) return; + _storyboard?.Stop(); _storyboard = new Storyboard(); - var animation = new DoubleAnimation(-ActualWidth, ActualWidth, Duration) + _elementPanel.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); + _elementPanel.Width = _elementPanel.DesiredSize.Width; + _elementPanel.Height = _elementPanel.DesiredSize.Height; + + var animation = new DoubleAnimation(-_elementContent.ActualWidth, ActualWidth, Duration) { RepeatBehavior = RepeatBehavior.Forever }; diff --git a/src/Shared/HandyControl_Shared/Themes/Styles/Base/RunningBlockBaseStyle.xaml b/src/Shared/HandyControl_Shared/Themes/Styles/Base/RunningBlockBaseStyle.xaml index 88a1a704..25343f76 100644 --- a/src/Shared/HandyControl_Shared/Themes/Styles/Base/RunningBlockBaseStyle.xaml +++ b/src/Shared/HandyControl_Shared/Themes/Styles/Base/RunningBlockBaseStyle.xaml @@ -2,19 +2,30 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:HandyControl.Controls"> -