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
65
XamCarouselListBox move item in the middle if clicked
posted

Hello,

I'm working at an C# WPF MVVM application with a XamCarouselListBox.

How can I archieve that the clicked item always moves to the middle?

Can I archieve this via XAML?

I always show 3 items at once with "ItemsPerPage = "3"".

Thanks,

Achim

Parents
  • 34510
    Verified Answer
    Offline posted

    Hi Achim,

    Unfortunately it's not currently possible to get this working with XAML only.  You will need to programmatically adjust what item is displayed as the main item in the carousel by using the XamCarouselListBox.ScrollInfo.SetHorizontalOffset() method.  This method takes in the index of the item where you want to set the offset and the offset will place the item at the beginning of the carousel path.  So if your path goes from left to right, the index you provide to the SetHorizontalOffset() method will place the item all the way to the left.  So assuming you have 3 items displayed per page you will want to set the horizontal offset to (index - 1), taking care to handle index wrapping issues when you get to the edges of your data.

    In order to keep MVVM you can put this logic into a Behavior<T> and then attach the behavior to the carousel in XAML.  This way you don't have any code in your code-behind.

Reply Children