Binding carousel with viewModel

2 posts, 1 answers
  1. Roquier Michael
    Roquier Michael avatar
    4 posts
    Member since:
    Sep 2009

    Posted 29 Sep 2009 Link to this post

    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>

     


     
  2. Answer
    Milan
    Admin
    Milan avatar
    1989 posts

    Posted 01 Oct 2009 Link to this post

    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.
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top