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

How to Bind data from XML Doc to my WPF RadCarousel

2 Answers 87 Views
Carousel
This is a migrated thread and some comments may be shown as answers.
Beesh
Top achievements
Rank 1
Beesh asked on 27 Jul 2009, 01:01 PM
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 Answers, 1 is accepted

Sort by
0
Accepted
Milan
Telerik team
answered on 27 Jul 2009, 04:41 PM
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.
0
Beesh
Top achievements
Rank 1
answered on 29 Jul 2009, 03:50 PM

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