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

How do I bind to a list of view models?

6 Answers 204 Views
Carousel
This is a migrated thread and some comments may be shown as answers.
Simplex
Top achievements
Rank 1
Simplex asked on 15 Jul 2009, 09:16 PM
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> 

6 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 20 Jul 2009, 04:35 PM
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.
0
Simplex
Top achievements
Rank 1
answered on 20 Jul 2009, 04:52 PM
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
0
Milan
Telerik team
answered on 21 Jul 2009, 09:06 AM
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.
0
Simplex
Top achievements
Rank 1
answered on 23 Jul 2009, 08:03 PM
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
0
Milan
Telerik team
answered on 24 Jul 2009, 05:26 AM
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.
0
Simplex
Top achievements
Rank 1
answered on 24 Jul 2009, 07:03 PM
Ticket created.

Thanks

Tags
Carousel
Asked by
Simplex
Top achievements
Rank 1
Answers by
Milan
Telerik team
Simplex
Top achievements
Rank 1
Share this question
or