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

5 posts, 0 answers
  1. James
    James avatar
    2 posts
    Member since:
    Aug 2010

    Posted 28 Jan 2011 Link to this post

    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
  2. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 02 Feb 2011 Link to this post

    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>>
  3. UI for WPF is Visual Studio 2017 Ready
  4. Robert
    Robert avatar
    271 posts
    Member since:
    Mar 2011

    Posted 15 Sep 2011 Link to this post

    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
  5. Maya
    Admin
    Maya avatar
    4062 posts

    Posted 16 Sep 2011 Link to this post

    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 >>

  6. Jonah
    Jonah avatar
    29 posts
    Member since:
    Oct 2012

    Posted 17 Dec 2012 Link to this post

    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.
Back to Top
UI for WPF is Visual Studio 2017 Ready