Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
XamCarouselListBox - change the item position in code
posted

I can't find, how to change the item position in the XAMCarouselListBox. I'd like to show the select item always in the middle of the path. The path is a simple horizontal line.

 

 

Parents
  • 20
    Offline posted

    I've solved this problem: I react on selection change and move there the items right or left:

    ....

    xamCarouselListBox1.SelectionChanged += new SelectionChangedEventHandler(xamCarouselListBox1_SelectionChanged);

    ....

    void xamCarouselListBox1_SelectionChanged(object sender, SelectionChangedEventArgs e) {

      int centerPos = xamCarouselListBox1.ViewSettings.ItemsPerPage / 2;

      int centerIndex=-1;

      for (int i=0; i<xamCarouselListBox1.Items.Count; i++) {

        CarouselListBoxItem clbi =    (CarouselListBoxItem)xamCarouselListBox1.RecyclingItemContainerGenerator.ContainerFromIndex(i);

        if (clbi != null && i==centerPos + xamCarouselListBox1.ScrollInfo.VerticalOffset) {

            centerIndex = i;

            break;

        }

      }

     

      int selectedOffset = xamCarouselListBox1.SelectedIndex - centerIndex;

     

      if (selectedOffset > 0) {

        for (int i=0; i<selectedOffset; i++) {

           xamCarouselListBox1.ScrollInfo.LineRight();

        }

      } else {

        for (int i=0; i<-selectedOffset; i++) {

           xamCarouselListBox1.ScrollInfo.LineLeft();

        }

      }

    }

Reply Children
No Data