LoopingList SelectedItem

8 posts, 0 answers
  1. Bruno
    Bruno avatar
    2 posts
    Member since:
    May 2011

    Posted 12 Jun 2011 Link to this post

    Hi,
    I'm new to XAML and WP development, so I might be missing something basic here.  I am using the same functionality as one of your examples, FirstLook.xaml.cs, where you animate the looping list to mimic a slot machine.  Once the animation stops, I get the SelectedIndexChanged event, but the selected index does not match the item that is centered.  How to get the selected item?

    Thanks.
  2. Bruno
    Bruno avatar
    2 posts
    Member since:
    May 2011

    Posted 12 Jun 2011 Link to this post

    Sorry for the post, I found the problem.  Sometimes the SelectedIdexChanged happens before the ScrollCompleted event, and I was relying on the later event to happen first (which is true most of the times).

    Cheers!
  3. DevCraft banner
  4. B1SHQP
    B1SHQP avatar
    11 posts
    Member since:
    Mar 2011

    Posted 06 Jul 2011 Link to this post

    Hi there, saw your Rad LoopingList SelectedItem post on the telerik forums, I too am using the control to spin a 1 armed bandit type display.

    But like you the selected item is not what is displayed in centre of the control when it has finished scrolling.

    I am making the looplist spin by setting a vertical offset, how are you making the loop list randomly spin?
  5. Deyan
    Admin
    Deyan avatar
    2041 posts

    Posted 12 Jul 2011 Link to this post

    Hello Andrew ,

    In order for the SelectedItem to be centered in the viewport of RadLoopingList, you should make sure that the IsCentered property of the control is set to true.

    Kind regards,
    Deyan
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  6. B1SHQP
    B1SHQP avatar
    11 posts
    Member since:
    Mar 2011

    Posted 12 Jul 2011 Link to this post

    Thanks for that,my actual problem is that I am using the verticaloffset to spin the loopinglist, this works well, but when the list stops spinning, the item that is shown in the view port of the looping panel is not the item that is at the selectedIndex.

    I was asking the question of the other dev 'how did they make the looping list spin?'

    Also DEYAN is using the verticalOffset the best way to make the list spin? It works really well, but I have the SelectedIndex problem.

    thanks for your help.
  7. Deyan
    Admin
    Deyan avatar
    2041 posts

    Posted 13 Jul 2011 Link to this post

    Hi Andrew ,

    You may find it useful taking a look at our FirstLook example for RadLoopingList. There we use the AnimateVerticalOffset method to animate the control. It is also automatically centered when the looping animation is finished:

    private void ScrollList(RadLoopingList list)
    {
        int duration = this.random.Next(1500, 3000);
        double offset = this.random.Next(3000, 5000);
     
        list.SelectedIndex = -1;
     
        list.AnimateVerticalOffset(list.VerticalOffset + offset, new Duration(TimeSpan.FromMilliseconds(duration)), new CubicEase());
    }


    Please note that if you wish the control to loop and eventually stop so that a specified item is selected, you will have to calculate the amount you would like to scroll considering the height of the viewport, as well as the height of a single item.

    I hope this helps.

    Best wishes,
    Deyan
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

  8. B1SHQP
    B1SHQP avatar
    11 posts
    Member since:
    Mar 2011

    Posted 13 Jul 2011 Link to this post

    So basically to get the index of the item that is in view after the scrolling has finished you have to calculate it using the offset and the height of the list item?

    I notice that on the looping list's loopPanel there is an index stored that seems to be that of the item in view after the scrolling has finished. However the loopPanel is private and cannot be accessed. How can I access the loopPanel's viewed item index?
  9. Deyan
    Admin
    Deyan avatar
    2041 posts

    Posted 14 Jul 2011 Link to this post

    Hi Andrew ,

    It seems that I have misunderstood your previous post.

    When the scrolling animation has finished, and provided that the IsCentered property is set to true, RadLoopingList will select the item that is also centered. So if you are animating RadLoopingList using the AnimateVerticalOffset the item in the middle of the viewport, i.e. the centered item should be the selected one after the end of the scrolling animation. You can access the index of this item by using the SelectedIndex property.

    Let me know if this is what you need.

    Greetings,
    Deyan
    the Telerik team

    Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Back to Top
DevCraft banner