private void UpdateAnimationRunning()
 {
     if (IsMarqueeAnimationRunning)
     {
         MarqueeAnimation.RepeatBehavior = RepeatBehavior.Forever;
         MarqueeStoryboard.Begin();
     }
     else
     {
         MarqueeAnimation.RepeatBehavior = new RepeatBehavior(0);
         MarqueeStoryboard.Stop();
     }
 }
        private void AdjustWidth()
        {
            AnimatedTextBlock.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity));
            double           textWidth    = AnimatedTextBlock.DesiredSize.Width;
            double           widthToBeSet = AnimatedTextBlock.ActualWidth;
            FrameworkElement parent       = Parent as FrameworkElement;

            if (parent != null)
            {
                widthToBeSet = parent.ActualWidth < AnimatedTextBlock.ActualWidth ? AnimatedTextBlock.ActualWidth : parent.ActualWidth;
                MarqueeStoryboard.Stop();
                AdjustAnimationDuration();
                Width = widthToBeSet;
                MarqueeAnimation.To   = -AnimatedTextBlock.DesiredSize.Width;
                MarqueeAnimation.From = parent.ActualWidth == 0 ? KOutOfTheScreenWidth : parent.ActualWidth; // Workaround: To avoid flicker on screen show up
                MarqueeStoryboard.Begin();
            }
        }
 public void OnLoaded(object sender, RoutedEventArgs args)
 {
     (Parent as FrameworkElement).SizeChanged += OnContainerSizeChanged;
     AdjustWidth();
     MarqueeStoryboard.Begin();
 }