Gustavo's profilementasBlogListsSkyDrive Tools Help
    November 15

    Ticker

    You can use this panel as ItemsPanelTemplate on ItemsControl, ListBox, ...
    Note: For a better control over delta FPS use a Storyboard instead DispatcherTimer.
     

    public class Ticker : Canvas

    {

        public static readonly DependencyProperty DelayProperty;

        public static readonly DependencyProperty DeltaProperty;

     

        private double pos = 0;

     

        static Ticker()

        {

            DelayProperty = DependencyProperty.Register("Delay", typeof(TimeSpan), typeof(Ticker), new PropertyMetadata(TimeSpan.Zero));

            DeltaProperty = DependencyProperty.Register("Delta", typeof(double), typeof(Ticker), new PropertyMetadata(2.0));

        }

     

        public Ticker()

            : base()

        {

            ClipToBounds = true;

     

            Loaded += new RoutedEventHandler(Ticker_Loaded);

        }

     

        public void Ticker_Loaded(object sender, RoutedEventArgs e)

        {

            foreach (FrameworkElement fe in Children)

            {

                pos = ActualWidth;

                Canvas.SetLeft(fe, ActualWidth);

            }

     

            DispatcherTimer delay_timer = new DispatcherTimer() { Interval = Delay };

            delay_timer.Tick += delegate

            {

                DispatcherTimer delta_timer = new DispatcherTimer() { Interval = TimeSpan.FromMilliseconds(10) };

                delta_timer.Tick += delegate

                {

                    foreach (FrameworkElement fe in Children)

                    {

                        pos -= Delta;

                        if (pos + fe.ActualWidth < 0)

                            pos = ActualWidth;

     

                        Canvas.SetLeft(fe, pos);

                    }

                };

                delta_timer.Start();

     

                delay_timer.Stop();

            };

            delay_timer.Start();

        }

     

        [Category("Ticker")]

        public TimeSpan Delay

        {

            get { return (TimeSpan)GetValue(DelayProperty); }

            set { SetValue(DelayProperty, value); }

        }

        [Category("Ticker")]

        public double Delta

        {

            get { return (double)GetValue(DeltaProperty); }

            set { SetValue(DeltaProperty, value); }

        }

    }

    Comments

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.
    Gustavo Arranhado has turned off comments on this page.

    Trackbacks

    The trackback URL for this entry is:
    http://mentas.spaces.live.com/blog/cns!A8D899E9B03A6E15!792.trak
    Weblogs that reference this entry
    • None