10 Answers, 1 is accepted
With your current setup, you can set the SelectedIndex of the ListBox to 0 and the first item would be brought into view in the RadCarousel.
I am not sure of your requirements but the overall setup of your sample application does not seem correct. You can bind the SelectedItem of the RadCarousel to the SelectedItem of the ListBox. Furthermore, you should handle the SelectionChanged event of the ListBox and set the SelectedItem of the RadCarousel and bring it into view.
I have updated the sample and attached it. Please review it and consider such approach.
Regards,
Stefan Nenchev
Telerik by Progress
That wouldn't work as the selected item in the list box has it's own list which is the one that is shown in the carousel view.
I've substituted random strings for the actual values that I'll be using in our actual product.
e.g. the list box contains a list of users, and the carousel could contain their bookings, clients, permissions, etc.
I've just looked at your changes, and the changes that you've made
a) stop the application being MVVM compatible and
b) don't work if you change the UI back to the carousel having a datacontext of the listbox selected item
You can easily modify the sample I have added to be MVVM. Please review the following blog post - Extending the Functionality of RadControls with Attached Properties. I have further modified the demo sample as well. Why would not the suggested approach work for you? Please update me whether I am missing something.
Regards,
Stefan Nenchev
Telerik by Progress
By changing the the RadCarousel Datacontext to SelectedItem you've changed the functionality of the demo app.
Original :
<telerik:RadCarousel DataContext="{Binding SelectedItem, ElementName=listBox}" ItemsSource="{Binding Items}" ItemTemplate="{DynamicResource DataTemplate1}"/>
Your Change :
<telerik:RadCarousel SelectedItem="{Binding SelectedItem, ElementName=listBox, Mode=OneWayToSource}" x:Name="radCarousel" local:CarouselAttachedBehavior.LoadAttachedBehavior="true" ItemsSource="{Binding Items}"></telerik:RadCarousel>
The change you've made means that you're showing the same collection twice, rather than showing the child collection of the selected item in the list box.
Thus, you've not actually answered the problem that I've got, you've answered a much simpler problem that you've got examples of in your demo app.
Changing the DataContext of the whole RadCarousel to be the selected item of the ListBox would not be the way to go here. You can use the ItemTemplate of the RadCarousel to show the additional information of the object. Please have a look at the updated sample.
Regards,
Stefan Nenchev
Telerik by Progress
But that doesn't work in many use cases.
e.g. a list of photo albums where the control is showing the photos in that album, a list of playlists again where the control is showing the songs in the play list, in fact any Master>Child list setup where you want to show the child list in the carousel control.
At this point the only way to do this is to change the items source in some way. Please try to solve the problem that I'm actually having rather than changing the problem into something that's easy to solve (and is no longer the problem that I'm trying to solve)
Thank you for the clarification.Indeed, I was thinking that the scenario you aim for is different. Excuse me for that. Please check the modified sample as the approach there should suit your needs.
Regards,
Stefan Nenchev
Telerik by Progress