This is a migrated thread and some comments may be shown as answers.

How to make the Center (top) item be the first item in list by default

10 Answers 291 Views
Carousel
This is a migrated thread and some comments may be shown as answers.
Phoenix
Top achievements
Rank 1
Phoenix asked on 10 Nov 2016, 01:50 PM

How do I get the first item in the list to be the top most item in the carousel view by default?

I've uploaded a sample project here - https://1drv.ms/u/s!AlTc1v3Zi2qjiad16m_HibRZA6awag

 

10 Answers, 1 is accepted

Sort by
0
Stefan Nenchev
Telerik team
answered on 14 Nov 2016, 10:57 AM
Hi Andrew,

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
Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
0
Phoenix
Top achievements
Rank 1
answered on 17 Nov 2016, 11:09 AM

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.

0
Phoenix
Top achievements
Rank 1
answered on 18 Nov 2016, 10:32 AM

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

0
Stefan Nenchev
Telerik team
answered on 21 Nov 2016, 11:38 AM
Hi Аndrew,

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
Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
0
Phoenix
Top achievements
Rank 1
answered on 21 Nov 2016, 12:11 PM

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.

 

0
Stefan Nenchev
Telerik team
answered on 22 Nov 2016, 03:35 PM
Hello,

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
Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
0
Phoenix
Top achievements
Rank 1
answered on 23 Nov 2016, 09:35 AM

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)

0
Stefan Nenchev
Telerik team
answered on 24 Nov 2016, 10:46 AM
Hi Andrew,

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
Telerik UI for WPF is ready for Visual Studio 2017 RC! Learn more.
0
Phoenix
Top achievements
Rank 1
answered on 24 Nov 2016, 11:01 AM
Thanks, that seems to work I'll see how it looks in the production code :)
0
Phoenix
Top achievements
Rank 1
answered on 24 Nov 2016, 11:23 AM
That's working in the main code as well, thanks for your help :)
Tags
Carousel
Asked by
Phoenix
Top achievements
Rank 1
Answers by
Stefan Nenchev
Telerik team
Phoenix
Top achievements
Rank 1
Share this question
or