-
Notifications
You must be signed in to change notification settings - Fork 1.9k
[Bug] Unable to set initial CarouselView item using ScrollTo() in page constructor #7268
Comments
We are still working on CarouselView, but you just need to set the Position no need to call ScrollTo, Will that work for you?
|
I'm not seeing Carousel.Position in current builds, but I honestly wouldn't think to look for it. I'd expect SelectedIndex and/or SelectedItem like in CarouselPage, TabbedPage, Picker and ListView. Does any other control have a Position property? In fact, SelectedItem is much more useful for the MVVM design pattern. |
Hi there's a |
Hi, I don't have a I'm having the same problem with the ScrollTo() when initializing the component. |
@Julingska Please try 4.3.0-pre1. Thank you! |
Bug is still present in 4.3.0.778476-pre1. |
@samhouts @Julingska : Bug still present in 4.3.0.851321-pre3 when using ScrollTo(). However, you can now use CurrentItem successfully in the constructor. |
@Magendanz Can you please attach a small project that demonstrates this issue? Thanks! |
Are you unable to reproduce? I thought the code segments above were pretty clear. |
Taken the liberty to create a reproduction based on the code provided. Does indeed not seem to work while setting |
So, I think the underlying problem here is with animation. This is on by default, so just calling However, if you call with the |
For this case you should just set the Position.
|
Well, the workaround is to set the CurrentItem and ensure IsScrollAnimated="False", but that's gotten me unblocked for the past year. |
Description
A common practice when initializing a CarouselView is to assign the ItemsSource and then set the initial selection with ScrollTo(object item) in the page constructor. This doesn't work.
Steps to Reproduce
...where Carousel is the x:Name assigned in XAML.
Expected Behavior
The ScrollTo() call should set the initial selected item to be item.
Actual Behavior
The first item in the collection ends up being selected and the ScrollTo() is ignored.
Basic Information
The workaround is to place the ScrollTo() call in an Appearing event handler. This, however, causes a messy sequence of selections, starting with the first item in the colleciton, followed by the second item, and then finally the target item. Animations make this very distracting.
Note that this would all be much simpler if CarouselView inherited from SelectedItemsView so that we could just bind the SelectedItem to a property in our ViewModel.
The text was updated successfully, but these errors were encountered: