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

11 posts, 0 answers
  1. Phoenix
    Phoenix avatar
    15 posts
    Member since:
    Feb 2015

    Posted 10 Nov 2016 Link to this post

    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

     

  2. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    540 posts

    Posted 14 Nov 2016 Link to this post

    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!
  3. Phoenix
    Phoenix avatar
    15 posts
    Member since:
    Feb 2015

    Posted 17 Nov 2016 in reply to Stefan Nenchev Link to this post

    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.

  4. Phoenix
    Phoenix avatar
    15 posts
    Member since:
    Feb 2015

    Posted 18 Nov 2016 in reply to Stefan Nenchev Link to this post

    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

  5. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    540 posts

    Posted 21 Nov 2016 Link to this post

    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.
  6. Phoenix
    Phoenix avatar
    15 posts
    Member since:
    Feb 2015

    Posted 21 Nov 2016 in reply to Stefan Nenchev Link to this post

    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.

     

  7. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    540 posts

    Posted 22 Nov 2016 Link to this post

    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.
  8. Phoenix
    Phoenix avatar
    15 posts
    Member since:
    Feb 2015

    Posted 23 Nov 2016 in reply to Stefan Nenchev Link to this post

    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)

  9. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    540 posts

    Posted 24 Nov 2016 Link to this post

    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.
  10. Phoenix
    Phoenix avatar
    15 posts
    Member since:
    Feb 2015

    Posted 24 Nov 2016 in reply to Stefan Nenchev Link to this post

    Thanks, that seems to work I'll see how it looks in the production code :)
  11. Phoenix
    Phoenix avatar
    15 posts
    Member since:
    Feb 2015

    Posted 24 Nov 2016 in reply to Stefan Nenchev Link to this post

    That's working in the main code as well, thanks for your help :)
Back to Top