Silverlight Marquee Control
My previous post describes about making a Custom marquee control in WPF. Here is what I tried the same using Silverlight. Silverlight is getting really mature with its latest releases, it has come pretty close to WPF in most of the scenarios.
There is a difference with the way you create the Generic.xaml for writing the default look. You have to manually add the Generic.xaml to the project and set the build action as Resource file. See this blog for a detailed explanation of this. And the XAML code is still the same as what we wrote in WPF. The following code has to be added to the constructor so that whenever the control gets instantiated the default style will be associated with that.
public Marquee()
{
Live Demo Url
Source Code can be downloaded here
There is a difference with the way you create the Generic.xaml for writing the default look. You have to manually add the Generic.xaml to the project and set the build action as Resource file. See this blog for a detailed explanation of this. And the XAML code is still the same as what we wrote in WPF. The following code has to be added to the constructor so that whenever the control gets instantiated the default style will be associated with that.
public Marquee()
{
DefaultStyleKey = typeof(Marquee);
}The rest of the code is pretty much the same as WPF. I have added a Duration dependency property so that end user will be able to change the speed of the animation at run time. And subscribed to the mouse enter and leave so that animation will just stoped if the mouse is on top of the control.
Live Demo Url
Source Code can be downloaded here
Comments
jim
if (sb.Children.Count == 0)
{
sb.Children.Add(da);
Storyboard.SetTargetProperty(da, new PropertyPath("(Canvas.Left)"));
Storyboard.SetTarget(da, cp);
sb.Begin();
}
else
{
sb.Stop();
sb.Begin();
}
Great work. I tried to modify it in order to add dynamic text in runtime but it does not seem to work... somehow the animation restarts before reaching the end of the new text. Any idea on how to fix that?
Thank you.
Best regards,
Filipe
I managed to do that and now it seems just fine. I'm am kind of new to WPF and Silverlight, just getting into it now and I have another question... There is a gap when the text is scrolling, i.e., it only starts scrolling again after it reaches the end of the animation and I would like to get effect of continuous text. Do know how that can be accomplished? Maybe with two animations or something like that?
Thank you for you help.
Best regards,
Filipe Barrenho
Thanks!!
I like the demo but the download URL is not working. Can you please repost?