I have a WPF application which has a textblock at the bottom of the page. I want to animate this block so it scrolls along the bottom. I need to do this in code so that when it scrolls of screen it will change position to the other side when it's canvas is less than 0 - it's width as I also change the text at this point. This will loop. I did the exact same thing in a silverlight application with a storyboard and it worked perfectly. The code I used is as follows:
private Storyboard _newsScrollTimer = new Storyboard();
_newsScrollTimer.Duration = TimeSpan.FromMilliseconds(0);
_newsScrollTimer.Completed += new EventHandler(Animation);
_newsScrollTimer.Begin();
private void Animation(object sender, EventArgs e)
{
try
{
//Moves the news item using its canvas property.
NewsItem.SetValue(Canvas.LeftProperty, (double)NewsItem.GetValue(Canvas.LeftProperty) - 1.5);
_newsScrollTimer.Begin();
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
}
This works perfectly fine in my silverlight app, however it won't work at all in WPF. If I change the timespan value to 1 it will work for a few seconds and then stop suddenly. It stops at a different place each time. How do I modify this code so it will work for WPF. Alternatively could you tell me another way to animate a textblock smoothly. I tried using a dispatch timer instead which works, but the animation is jerky in places. Thanks in advance.