question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Carousel View sets selected index to 0 on init even though selected item is not index 0

See original GitHub issue

I am in a situation where I am trying to load a page with the CarouselView at the position that the user was in when they last left the page (or closed the application). I am doing this by binding the SelectedItem to the last selected item in the carousel’s bound list. What is happening though is that the CarouselView always starts at index 0 regardless of what the SelectedItem is bound to and then will change the SelectedItem to match the index.

When I put a break point in the property changed event, to observe what is happening, I am noticing that the carousel starts with the correct selected item but with an index of -1, since I am loading a list and the selected item gets bound before the list is done loading. I guess since the Item isnt found in the empty list it sets the index to -1. I am assuming that after the page is done initializing it sets that -1 to 0? and then that updates the SelectedItem as a consequence. I have tried to set the binding of SelectedItem after the ItemSource property changed but this doesnt work either.

I might be wrong in that assessment but I guess my question is: is it possible to drive the carousel from a bound SelectedItem? or do I have to bind to the SelectedIndex to get the kind of behavior I am wanting?

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:12 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
Jcook65commented, Feb 19, 2021

hey @AndreiMisiukevich, sorry for the delayed response. I actually ended up just converting the selected item to and index and binding to the SelectedIndex instead of the SelectedItem and it works fine now. I haven’t had the time to go back and try it the way you suggested here. I must’ve missed that property on the carousel but it sounds like it would help this situation. Thank you for the swift response!

0reactions
InquisitorJaxcommented, Mar 31, 2021

I’ll open a new ticket, thanks Andrei. So we bind ItemSource to generic List<T>, and Selected Index. Attaching the project ot debug is a good idea - I’ll try that, and report what I find.

Read more comments on GitHub >

github_iconTop Results From Across the Web

CarouselView doesn't scroll to the CurrentItem when set
Because it has just been attached the scroll position is invariably 0 and it always decides it has item 0 selected and stomps...
Read more >
Carousel image on different page with onPressed index
ANSWER VERSION 2.0. See, the UI element works correct, what needs to be done, is to find a way out to set the...
Read more >
Wrong behavior ComboBox using SelectedIndex
Hello, I am trying set SelectedIndex = -1 to set empty item on ComboBox. It is works fine in Q2, but after upadate...
Read more >
Carousel · Bootstrap v5.1
A slideshow component for cycling through elements—images or slides of text—like a carousel. On this page. How it works; Example. Slides only; With...
Read more >
ComboBox.SelectedIndex Property (System.Windows.Forms)
This property indicates the zero-based index of the currently selected item in the combo box list. Setting a new index raises the SelectedIndexChanged...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found