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

Binding carousel with viewModel

1 Answer 74 Views
Carousel
This is a migrated thread and some comments may be shown as answers.
Roquier Michael
Top achievements
Rank 1
Roquier Michael asked on 29 Sep 2009, 09:13 AM
Hi,
i'm  trying to bind a carousel with a CarouselDataRecordPresenter.

  • When i'm binding with a datatable, it's OK ( detail code see 1))
  • When i'm binding with an objet, the carousel have 2 elements but the property Lib of my object CarouselViewModel is not displayed ( detail code see 2).

     Remark:

     my visual Studio show me a error "Type or property expected " for the Data when i write the  Binding         Path=Data.CarouselViewModel.Lib

    When i don't use the  CarouselDataRecordPresenter, the carousel displays 2 elements with the name of property (LIB) and its Value.
    I tried other type of binding like Data[0] or Fields[Lib)..., but it doesn't work.  
    What's wrong with my binding? 

    Can you help me?

    1) BINDING with DATATABLE
    When i bind a carousel with a datatable , the carousel display the item of my row :
    In my code behind :

DataTable

 

dt = new DataTable();

 

 

DataColumn dc = new DataColumn("Lib");

 

dt.Columns.Add(dc);

 

DataRow dr = dt.NewRow();

 

dr[

"Lib"] = "Item1";

 

dt.Rows.Add(dr);

dr = dt.NewRow();

dr[

"Lib"] = "Item2";

 

dt.Rows.Add(dr);

sampleRadCarousel.ItemsSource = dt;

In my Xaml :

 

 

<Style TargetType="{x:Type Controls:CarouselDataRecordPresenter}">

 

 

 

<Setter Property="Template">

 

 

 

<Setter.Value>

 

 

 

<ControlTemplate TargetType="{x:Type Controls:CarouselDataRecordPresenter}">

 

 

 

<StackPanel Margin="0,20,0,0" TextElement.FontWeight="Bold">

 

 

 

<Label Content="{Binding Path=Data[Lib]}"/>

 

 

 

<Label Content="test"/>

 

 

 

</StackPanel>

 

 

 

</ControlTemplate>

 

 

 

</Setter.Value>

 

 

 

</Setter>

 

 

 

</Style>

 

2) BINDING MODELVIEW
In code behind 

Collection

 

<CarouselViewModel> ListeCarousel = new Collection<CarouselViewModel>();

 

 

CarouselViewModel carouselview = new CarouselViewModel("item1");

 

ListeCarousel.Add(carouselview);

 

CarouselViewModel carouselview1 = new CarouselViewModel("item2");

 

ListeCarousel.Add(carouselview1);

sampleRadCarousel.ItemsSource = ListeCarousel;

In xaml :

 

 

<Style TargetType="{x:Type Controls:CarouselDataRecordPresenter}">

 

 

 

<Setter Property="Template">

 

 

 

<Setter.Value>

 

 

 

<ControlTemplate TargetType="{x:Type Controls:CarouselDataRecordPresenter}">

 

 

 

<StackPanel Margin="0,20,0,0" TextElement.FontWeight="Bold">

 

 

 

<Label Content="{Binding Path=Data.CarouselViewModel.Lib}"/>

 

 

 

<Label Content="2"/>

 

 

 

<Label Content="3"/>

 

 

 

</StackPanel>

 

 

 

</ControlTemplate>

 

 

 

</Setter.Value>

 

 

 

</Setter>

 

 

 

</Style>

 


 

1 Answer, 1 is accepted

Sort by
0
Accepted
Milan
Telerik team
answered on 01 Oct 2009, 03:40 PM
Hi Roquier Michael,

A simple modification to your XAML is needed to display your data correctly:

<Label Content="{Binding Path=Data.Lib}"/>  
<!--Instead of --> 
<Label Content="{Binding Path=Data.CarouselViewModel.Lib}"/> 

Hope this works.

Best wishes,
Milan
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Carousel
Asked by
Roquier Michael
Top achievements
Rank 1
Answers by
Milan
Telerik team
Share this question
or