How to Create Ad Rotator with Telerik TransitionControl and CoverFlow control for Silverlight

Tuesday, January 11, 2011 by XAML Team | Comments 12

Today I'm going to show you a very simple way to turn any ContentControl or a ListBox control into an AdRotator control. "What is AdRotator control?", you would ask. A common definition for an AdRotator is a control that lets you to show some data (most commonly ads) and change it periodically. An AdRotator control should be a control that lets you do that out-of-the-box without writing any code. Furthermore, switching the ads with a nice animation will give our AdRotator more polished and glamorous look. To accomplish this, we are going to use RadTransitionControl (a ContentControl) and RadCoverFlow (a ListBox) in the demo.

Here is how the demo looks like with the RadTransitionControl:

and with the RadCoverFlow control:

How to create this?

I've prepared some attached properties that attach AdRotator behavior to a ListBox or to a ContentControl when set to one of them. I put them into a separate assembly to let you use them directly. In this post we are not going to discuss how the attached properties are implemented - the source code is included and you can take a look at it if you want to.

The properties are ItemsSource, ItemChangeDelay and SelectedIndex. The ItemsSource property holds the collection of ads or other items to be shown consequently, the ItemChangeDelay property determines the time each item will be displayed and the SelectedIndex property could be used to determine from which item to start showing. When the behavior is triggered, the SelectedIndex property is updated automatically.

What you need to do in order to use the behavior is first to set the ItemsSource attached property to some collection of items . Then,  after the XAML is parsed by the XAML parser, all it takes is to have the ItemsSource property explicitly set. Here is how you can put all this in action with RadTransitonControl (the first demo):

<telerik:RadTransitionControl adRotator:AdRotatorExtensions.ItemChangeDelay="0:0:3"
                        adRotator:AdRotatorExtensions.CurrentSelectedIndex="0"
                        VerticalAlignment="Center"
                        HorizontalAlignment="Center"
                        Width="700">
    <telerik:RadTransitionControl.Transition>
        <telerik:MotionBlurredZoomTransition />
    </telerik:RadTransitionControl.Transition>
    <adRotator:AdRotatorExtensions.ItemsSource>
        <adRotator:AdsCollection>
            <Image Source="/Banners/1_AJAX_Slide.jpg" />
            <Image Source="/Banners/2_MVC_Slide.jpg" />
            <Image Source="/Banners/3_SL_Slide.jpg" />
            <Image Source="/Banners/4_WF_Slide.jpg" />
            <Image Source="/Banners/5_WPF_Slide.jpg" />
            <Image Source="/Banners/6_REP_Slide.jpg" />
            <Image Source="/Banners/7_ORM_Slide.jpg" />
            <Image Source="/Banners/8_JC_Slide.jpg" />
            <Image Source="/Banners/9_JM_Slide.jpg" />
        </adRotator:AdsCollection>
    </adRotator:AdRotatorExtensions.ItemsSource>
</telerik:RadTransitionControl>


Hope this will help you to create more impressive applications!

You can download the whole demo with the source code of the attached properties from here.

12 Comments

  • Ben 12 Jan 2011
    Miro, this AdRotatorExtension is awesome :-) I highly suggest to to be part of Telerik Toolkit, because this is very much needed on front page websites or web applications.

    Thanks for the great extension.
    ..Ben
  • Miroslav Nedyalkov 14 Jan 2011
    Hi Ben,
    I'm glad to hear you like it! We will consider your suggestion.

    Regards!
  • Mart 21 Apr 2011
    Hi,



    Since I upgraded to Telerik 2011 Q1 (WPF), this extension becomes erractic. For exemple, if I have two Items in the collection, set with a transition delay of 10 seconds, sometime I see the Item for 10s, and the second items for 2 seconds only. Do you know if a changed occured in transition control that can affect your extension?  I wasn't able to reproduce this behavior in a new application, but I can't. In the same page, I have 4 AdRotatorExtension setup with different timers.
  • Mla 04 May 2011
    I have 1 AdRotator in my WPF application. I upgarded to 2011 Q1, and now the extension is not working correctly. I put some trace in the extension:



    [OnItemsSourceChanged: 13:53:51.463] Telerik.Windows.Controls.RadTransitionControl

    [OnElementLoaded: 13:53:51.880] Telerik.Windows.Controls.RadTransitionControl -> Timer.Interval = 00:00:25

    [OnElementLoaded: 13:54:00.185] Telerik.Windows.Controls.RadTransitionControl -> Timer.Interval = 00:00:25

    [MoveToNextElement: 13:54:16.878] currentIndex = 0

    [MoveToNextElement: 13:54:25.198] currentIndex = 1

    [MoveToNextElement: 13:54:41.982] currentIndex = 0

    [MoveToNextElement: 13:54:50.294] currentIndex = 1

    [MoveToNextElement: 13:55:07.081] currentIndex = 0

    [MoveToNextElement: 13:55:15.378] currentIndex = 1

    [MoveToNextElement: 13:55:32.180] currentIndex = 0

    [MoveToNextElement: 13:55:40.463] currentIndex = 1

    [MoveToNextElement: 13:55:57.366] currentIndex = 0



    As you can see, the Timer.Interval is set to 25 sec, but the delay between MoveToNextElement call is 8.3 sec and 16.7 sec (25 sec total?!). If I set Timer.Interval to 45, I will get the first element for 8.3 sec and teh second element for 16.7 sec. Any Idea?

  • Miroslav Nedyalkov 10 May 2011
    Hello,

    Thank you for reporting us this problems - we will investigate this issue.

    Regards,
    Miroslav N.
  • Brad 13 Aug 2011
    What about transitioning between templates. I am trying to reproduce an Ad Rotator I had in the Telerik AJAX toolkit that was linked to Database Records (i.e. Text on the template would change, but there were a few static images)
  • hema 30 Jan 2012
    how to use this telerik control in Silver Light.
  • Miroslav Nedyalkov 30 Jan 2012
    Brad, what you need is supported throught the ContentTemplate property of the RadTransionControl.
    Hema, the sample attached to this post is for Silverlight. You could also refer to the followight help article: http://www.telerik.com/help/silverlight/radtransition-overview.html.
  • John 04 Feb 2012
    Can you please tell me how to bind a custom class with this control. My class have other information regarding ad along with the image property.
    I am using v2011.1.322.35 of telerik component.Will it cause any problem to the adRotator.
  • John 04 Feb 2012
    Can you please tell me how to bind a custom class with this control. My class have other information regarding ad along with the image property.
    I am using v2011.1.322.35 of telerik component.Will it cause any problem to the adRotator.
  • Michele 10 Feb 2012
    I add my request to the one unresolved from John...
    How do you dinamically set the ItemsSource of the RotatorExtensions?
    In the sample at http://blogs.telerik.com/blogs/posts/11-01-11/how-to-create-ad-rotator-with-telerik-transitioncontrol-and-coverflow-control-for-silverlight.aspx you have a static defined list of <Image> but what about extracting it at runtime?
    I've tried using RotatorExtensions.SetItemsSource(rotatorControl, myImageCollection) but it seems not working.
  • Michele 10 Feb 2012
    I add my request to the one unresolved from John...
    How do you dinamically set the ItemsSource of the RotatorExtensions?
    In the sample at http://blogs.telerik.com/blogs/posts/11-01-11/how-to-create-ad-rotator-with-telerik-transitioncontrol-and-coverflow-control-for-silverlight.aspx you have a static defined list of <Image> but what about extracting it at runtime?
    I've tried using RotatorExtensions.SetItemsSource(rotatorControl, myImageCollection) but it seems not working.

Add comment

  1. Formatting options
       
     
     
     
     
       
  2. (optional, emails won't be shown on public pages)
  3. (optional)