How do I bind to a list of view models?

7 posts, 0 answers
  1. Simplex
    Simplex avatar
    12 posts
    Member since:
    Jun 2009

    Posted 15 Jul 2009 Link to this post

    I can't get it to display a list of objects which are view models.
    Using version 2009.2.701.35 with vb.net in a model/view/view model framework.

    This displays nothing:
                <telerik:RadCarousel  
                    x:Name="RCAddressList" 
                    ItemsSource="{Binding Path=AddressViewModelList}" 
                    telerik:StyleManager.Theme="Office_Blue"
                </telerik:RadCarousel 

    This displays the correct number of items, but it is just then name of the object. i.e. 4 addresses in the list means  AddressApp.ViewModel.AddressViewModel as text 4 times in the carousel.
                <ListView  
                    x:Name="ListView"  
                    ItemsSource="{Binding Path=AddressViewModelList}"  
                    BorderThickness="0" Background="Transparent" 
                    HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
                    <ListView.ItemsPanel> 
                        <ItemsPanelTemplate> 
                            <telerik:RadCarouselPanel /> 
                        </ItemsPanelTemplate> 
                    </ListView.ItemsPanel> 
                </ListView> 

  2. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 20 Jul 2009 Link to this post

    Hi Edward,

    If you have just 4 items and you are working with the default items per page the carousel will not automatically display the items. You can use the navigation buttons to bring some items into view.

    All the best,
    Milan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. UI for WPF is Visual Studio 2017 Ready
  4. Simplex
    Simplex avatar
    12 posts
    Member since:
    Jun 2009

    Posted 20 Jul 2009 Link to this post

    It's not that it won't display. It is that instead of the control I get the text of the object. For example "MainApp.ViewModel.AddressViewModel" in the 4 slots instead of the actual control.

    The controls display fine if I use a ListView or ItemsControl and I'm binding to the same ItemsSource in all three cases.

    Do you have an example of using a carousel in a Model/View/ViewModel framework that binds to a list of View Model objects?

    Thanks
  5. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 21 Jul 2009 Link to this post

    Hi Edward,

    There is no problem to bind to ViewModel data - the only thing that you have to do is to modify the default
    CarouselDataRecordPresenter template. To display a ViewModel object you could do something like that:

    <Style TargetType="{x:Type telerik:CarouselDataRecordPresenter}">  
        <Setter Property="Template">  
            <Setter.Value> 
                <ControlTemplate TargetType="{x:Type telerik:CarouselDataRecordPresenter}">  
                        <StackPanel Margin="0,20,0,0" TextElement.FontWeight="Bold">  
                            <Label Content="{Binding Path=Data.ViewModelData.Sender}"/>  
                            <Label Content="{Binding Path=Data.ViewModelData.Subject}"/>  
                            <Label Content="{Binding Path=Data.ViewModelData.Size}"/>  
                        </StackPanel> 
                </ControlTemplate> 
            </Setter.Value> 
        </Setter> 
    </Style> 

    The CarouselDataRecordPresenter is the element that displays the contents of a data item. A binding to a property of the original data items should look like "{Binding Path=Data.ViewModelData.Size}" where the first property Data is the property of our DataRecord class (the DataContext), the second property ViewModelData is the ViewModel property that exposes the original data item and finally the last item is a property of a data item.

    Hope this helps.

    Kind regards,
    Milan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  6. Simplex
    Simplex avatar
    12 posts
    Member since:
    Jun 2009

    Posted 23 Jul 2009 Link to this post

    That still does not give what I need. I have created a small app to show the problem, how do I get that do you?

    Thanks
  7. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 24 Jul 2009 Link to this post

    Hello Edward,

    You can open a support ticket and send your project by attaching it to the ticket.
    Thanks for your time.

    Kind regards,
    Milan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  8. Simplex
    Simplex avatar
    12 posts
    Member since:
    Jun 2009

    Posted 24 Jul 2009 Link to this post

    Ticket created.

    Thanks

Back to Top
UI for WPF is Visual Studio 2017 Ready