Hello again,
I have another question about the Xam Carousel List Box item:
When selecting an item, it should be turned to the "front" automatically. An old solution found here was:
while (carousel.FirstVisibleItemIndex != desiredIndex) { if (carousel.FirstVisibleItemIndex < desiredIndex) { carousel.ExecuteCommand(XamCarouselPanelCommands.NavigateToNextItem); } else { carousel.ExecuteCommand(XamCarouselPanelCommands.NavigateToPreviousItem); } }
However, FirstVisibleItemIndex is no longer available as well as the ExecuteCommand Method ...?
another minor question: when I have a round number as "ItemsPerPage" setting, two elements are at the same level in the front. Is there a workaround, that I still can have only ONE selected item in the "pole position" at the front?
Thanks a lot,
Florian
Hello Florian,
Thank you for your post. I have been looking into it and I can say that you can still use this code. The FirstVisibleItemIndex Property is a Property of the XamCarouselPanel, not XamCarousleListBox. You can get the panel like this:
XamCarouselPanel carousel = Utilities.GetDescendantFromType(sender as DependencyObject, typeof(XamCarouselPanel), true) as XamCarouselPanel;
You can use this code in the XamCarouselListBox’ SelectionChanged event handler. As for the “pole position”, if the number is round there will be two items. The thing you can do is try to use your custom ItemPath (Property of the XamCarouselListBox’ ViewSettings). Please let me know if this helps you or you have further questions on this matter.
Looking forward for your reply.
Hello Stefan,
thanks a lot for your help.
In the meantime, I also found another solution by myself. The solution posted here has the problem that it jumps kind of hard to the selected item and does not "flow" very nice. My solution however does.
What I did is first:Save the current selected Index in the backing code of the xaml by:
private int currentSelected;
Constructor: currentSelected = Math.Abs(Model.Items.Count / 2)-1; (-1 because I have 10 items and I want to have the selected one to be the lower one)
And on the XamCarouselListBox_OnSelectionChanged Event i do:
var selectedItem = ((XamCarouselListBox)sender);
var newSelected = selectedItem.SelectedIndex;
var toTurn = currentSelected - newSelected;
currentSelected = newSelected;
CarouselListBox.ScrollInfo.SetHorizontalOffset(CarouselListBox.ScrollInfo.HorizontalOffset - toTurn);
The ScrollInfo SetHorizontalOffset turns it more nice and works just as well.
to make it more smooth you can add these before the setHorizontalOffset Method:
if (toTurn == Model.Items.Count-1) toTurn = -1;if (toTurn == -1*(Model.Items.Count - 1)) toTurn = 1;if (toTurn > 5) toTurn = (-1) * (Model.Items.Count - toTurn);
One Minor problem i however still have is that, since my carousel is continuous, if I go "back" (left from Index 4 below Index 0, so 4 to 8), the list kind of "reloads" itself. I guess this is just a minor problem because the toTurn value is not set correctly.
I hope this helps others as well :)
Best Regards,Florian
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well.
Thanks again.