adRotator using TransitionControl

1 posts, 0 answers
  1. John
    John avatar
    1 posts
    Member since:
    Feb 2012

    Posted 03 Feb 2012 Link to this post

    I have a Telerik transition control binding to a custom class, The transition control accepts needs an image as input.  Can you please tell me how can i bind explicitly telling the element name which have the image reference. Itemsource is an attached property. I have included the code below. I tried Path=AdImage but it did not worked.

    I was using http://blogs.telerik.com/blogs/posts/11-01-11/how-to-create-ad-rotator-with-telerik-transitioncontrol-and-coverflow-control-for-silverlight.aspx  to create an adrotator control.



    <telerik:RadTransitionControl  x:Name="radControl" adRotator:AdRotatorExtensions.ItemChangeDelay="0:0:3" 
     adRotator:AdRotatorExtensions.CurrentSelectedIndex="0"
                                  adRotator:AdRotatorExtensions.IndexChanged="{Binding TopItemCommand, Mode=OneWay}"
                                  adRotator:AdRotatorExtensions.ItemsSource="{Binding ImagePaths, Mode=OneWay,Path=AdImage}"
     VerticalAlignment="Center" 
     HorizontalAlignment="Center" Width="650">
    <telerik:RadTransitionControl.Transition>
    <telerik:MotionBlurredZoomTransition />
    </telerik:RadTransitionControl.Transition>

    </telerik:RadTransitionControl>


     public static readonly DependencyProperty ItemsSourceProperty =
        DependencyProperty.RegisterAttached("ItemsSource", typeof(IEnumerable), typeof(AdRotatorExtensions), new PropertyMetadata(null, OnItemsSourceChanged));
        
        private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        {
        var element = d as FrameworkElement;
           var itemsControl = d as ItemsControl; // this is always null it returns a RadTranisitionControl object which doesnt have DisplayMemberName property
       
        var oldValue = e.OldValue as IEnumerable;
        var newValue = e.NewValue as IEnumerable;
           
               if (element != null)
               {
                   if (oldValue != null)
                   {
                       // Detach the Ad Rotator functionality.
                       element.Loaded -= OnElementLoaded;
                       element.Unloaded -= OnElementUnloaded;
        
                       // If there is a timer attached, stop it.
                       var timer = GetTimer(element);
                       if (timer != null)
                       {
                           timer.Stop();
                       }
                   }
        
                   if (newValue != null)
                   {
                       // Attach the Ad Rotator functionality.
                       element.Loaded += OnElementLoaded;
                       element.Unloaded += OnElementUnloaded;
        
                       // If the target is an ItemsControl and its ItemsSource is not set, set it.
                       if (itemsControl != null && itemsControl.ItemsSource == null && itemsControl.Items.Count == 0)
                       {
                           itemsControl.ItemsSource = newValue;
                           itemsControl.DisplayMemberPath = "AdImage"; // will never reaches here
                       }
                   }
               }
           }
        
        
        private static void OnElementLoaded(object sender, RoutedEventArgs args)
        {
        var element = sender as DependencyObject;
        
        // Create the timer and hook-up to the events.
        var timer = new DispatcherTimer();
        timer.Interval = GetItemChangeDelay(element).TimeSpan;
        SetTimer(element, timer);
        
        timer.Tick += (s, e) => MoveToNextElement(element);
        
        timer.Start();
        
        // Make sure the currently pointed element is selected.
        UpdateCurrentlySelectedItem(element);
        }
        
        private static void UpdateCurrentlySelectedItem(DependencyObject element)
        {
        var contentControl = element as ContentControl;
           
        
        
           var source = GetItemsSource(element);
        
        // If there is no source we shouldn't do anything.
        if (source == null) return;
        
        // Find the actual index to be selected (if outside the boundaries of the collection)
        // and find the actual element to be selected.
        var convertedSource = source.Cast<object>();
        var currentIndex = GetCurrentSelectedIndex(element);
        var elementToSelect = convertedSource.ElementAtOrDefault(currentIndex);
        
                    ICommand updateValue = null;
                    if (contentControl != null)
                    {
                        updateValue = contentControl.GetValue(IndexChangedProperty) as ICommand;
                    }
        
                    if (updateValue != null)
                        if (updateValue.CanExecute(elementToSelect))
                        {
                            updateValue.Execute(elementToSelect);
                            
        
                        }
        
        
        // Update the cotnent of the ContentControl if attached to a ContentControl.
        if (contentControl != null)
        {
        contentControl.Content = elementToSelect;
                        
        }
        }
     
     
Back to Top