How to Bind data from XML Doc to my WPF RadCarousel

3 posts, 1 answers
  1. Beesh
    Beesh avatar
    2 posts
    Member since:
    Jul 2009

    Posted 27 Jul 2009 Link to this post

    I'm trying to bind data using XmlDataProvider to image item in radcarousel but it didn't work . i think that am doing something wrong or i miss something . what should i use to read xml file .
     

     

     

     

    <Grid.DataContext>   
        <XmlDataProvider x:Name="objectDataProvider" Source="People.xml" XPath="/People/Person" />    
    </Grid.DataContext> 
    <telerik:RadCarousel Margin="12,30,12,34" Name="radCarousel1" >    
       <telerik:RadCarousel.ContextMenu>   
            <ContextMenu AllowDrop="True" HasDropShadow="True" IsTabStop="True" />   
       </telerik:RadCarousel.ContextMenu>   
          <Image Source="{Binding XPath=ImageFile}"></Image>   
    </telerik:RadCarousel>   
     

     

     

    i would appreciate any help, thanks in advance. 

     

     

     

     

     

     

  2. Answer
    Milan
    Admin
    Milan avatar
    1989 posts

    Posted 27 Jul 2009 Link to this post

    Hi Beesh,

    You could try something like that:

    <Grid.Resources> 
        <Style TargetType="telerik:CarouselDataRecordPresenter">  
            <Setter Property="Template">  
                <Setter.Value> 
                    <ControlTemplate TargetType="telerik:CarouselDataRecordPresenter">  
                        <Border> 
                            <Image Source="{Binding Mode=OneWay, Path=Data.ChildNodes[0].InnerText}"/>  
                        </Border> 
                    </ControlTemplate> 
                </Setter.Value> 
            </Setter> 
        </Style> 
        <XmlDataProvider x:Key="dataSource" Source="People.xml" XPath="People/Person"/>  
    </Grid.Resources> 
    <telerik:RadCarousel ItemsSource="{Binding Source={StaticResource dataSource}}"/> 

    Probably the only interesting line of code here is the Source binding of our Image element. Since we are binding to Xml we actually bind the carousel to a list of XmlNodes or XmlElements. Data.ChildNodes[0] specifies that we want to bind to the first sub-element of the Person class, which in my case is ImageList. Of course if your XML data structure is different you can specify another number in ChildNodes.

    Hope this helps.

    Greetings,
    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. Beesh
    Beesh avatar
    2 posts
    Member since:
    Jul 2009

    Posted 29 Jul 2009 Link to this post


    Millon thanks
Back to Top