This is a migrated thread and some comments may be shown as answers.

Stop scrolling left when first item is in the centre (topmost)

4 Answers 179 Views
Carousel
This is a migrated thread and some comments may be shown as answers.
James
Top achievements
Rank 1
James asked on 28 Jan 2011, 12:12 PM
Hi,

I want the carousel to stop scrolling left when the first item is in the centre of the screen (the topmost item).
I also want the carousel to stop scrolling right when the last item is in the centre of the screen (the topmost item).

Currently, you can continue scrolling left/right until the first or last item is on the extreme left or right of the screen.

Is there anyway to do this?

Also, is there anyway of setting the carousel to wrap around when you come to the end of the items?

Thanks

4 Answers, 1 is accepted

Sort by
0
Maya
Telerik team
answered on 02 Feb 2011, 03:43 PM
Hello James,

I am sending you a sample project illustrating how you may achieve the desired result. Let me know in case it does not meet your requirements.

Kind regards,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Robert
Top achievements
Rank 1
answered on 16 Sep 2011, 02:50 AM
Hi there,

I tried your example as it works when moving through the items using the control buttons, however when scrolling with the mouse scroll wheel it still continues past the first and last items.

Are you able to stop as required when using the mouse scroll wheel?

Thanks,

Rob
0
Maya
Telerik team
answered on 16 Sep 2011, 01:43 PM
Hello Robert,

That would be the expected behavior since the logic for moving till the centered item is implemented only for the Click events of the buttons. If you want to get similar behavior when scrolling, you can try to handle ScrollChanged event of the ScrollViewer and implement the required logic:

<telerik:RadCarouselScrollViewer.ScrollChanged="RadCarousel_ScrollChanged"/>
 

Best wishes,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Jonah
Top achievements
Rank 1
answered on 17 Dec 2012, 10:07 PM
Just wanted to post here just in case anyone else is looking for a solution to this. In your selectionChanged event of your Carousel you can determine if you can go right or left such as
if (sgCarousel.SelectedItem != null)       
{         
int index = sgCarousel.Items.IndexOf(sgCarousel.SelectedItem);         
if (index == 0)         
{           
_canGoRight = false;         
}        
 else       
  {       
    _canGoRight = true;     
    }     
    if (sgCarousel.Items.Count - 1 == index)
        {       
    _canGoLeft = false;  
       }        
 else     
    {      
     _canGoLeft = true;    
     }     
  }
Then in your PreviewMouseWheel event you can do the following
if (e.Delta < 0 && !_canGoLeft)    
   {      
   e.Handled = true;   
    }     
  if (e.Delta > 0 && !_canGoRight)      
 {       
  e.Handled = true;   
    }
This should make it so you always have an item on top.
Tags
Carousel
Asked by
James
Top achievements
Rank 1
Answers by
Maya
Telerik team
Robert
Top achievements
Rank 1
Jonah
Top achievements
Rank 1
Share this question
or