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

[Solved] How do i bind a legend in a datatemplate?

1 Answer 154 Views
Chart for XAML
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Bill
Top achievements
Rank 1
Bill asked on 26 Aug 2013, 07:47 AM
I have a datatemplate with a number of pie charts.  
I'd like to show a legend with each one of them.  
The samples show binding to a chart by name which is not available in the datatemplate.  
Do you have any suggestions for how to bind the legend?  


<
DataTemplate x:Key="PieGraphTemplate1">
     <Grid HorizontalAlignment="Left" Width="400" Height="400">
         <Border>
             <TelerikChart:RadPieChart PaletteName="DefaultDark" Margin="10,0">
                     <TelerikChart:DoughnutSeries ItemsSource="{Binding Items}">
                         <TelerikChart:DoughnutSeries.ValueBinding>
                             <TelerikChart:PropertyNameDataPointBinding PropertyName="Value"/>
                         </TelerikChart:DoughnutSeries.ValueBinding>
                     <TelerikChart:DoughnutSeries.LegendTitleBinding >
                         <TelerikChart:PropertyNameDataPointBinding PropertyName="Name"/>
                     </TelerikChart:DoughnutSeries.LegendTitleBinding>
                 </TelerikChart:DoughnutSeries>
             </TelerikChart:RadPieChart>
         </Border>
         <TelerikPrimitives:RadLegendControl LegendProvider="{Binding ????}"  >
             <TelerikPrimitives:RadLegendControl.ItemsPanel>
                 <ItemsPanelTemplate>
                     <StackPanel Orientation="Vertical"/>
                 </ItemsPanelTemplate>
             </TelerikPrimitives:RadLegendControl.ItemsPanel>
             <TelerikPrimitives:RadLegendControl.ItemTemplate>
                 <DataTemplate>
                     <StackPanel Orientation="Horizontal">
                         <Ellipse Fill="{Binding Fill}" Stroke="{Binding Stroke}" StrokeThickness="1" Width="20" Height="20"/>
                         <TextBlock Text="{Binding Title}" Foreground="{Binding Fill}"  Margin="10" FontStyle="Italic" FontSize="22"/>
                     </StackPanel>
                 </DataTemplate>
                 </TelerikPrimitives:RadLegendControl.ItemTemplate>
         </TelerikPrimitives:RadLegendControl>
     </Grid>
 </DataTemplate>

1 Answer, 1 is accepted

Sort by
0
Ivaylo Gergov
Telerik team
answered on 26 Aug 2013, 03:50 PM
Hello Bill,

Thank you for your interest.

In the current scenario I can see that both the LegendControl and the Chart are in the DataTemplate, so ElementName binding should work as expected. For your convenience, I have attached a project that demonstrates this scenario. Please, see the attached file.

I hope this helps. Let me know should you have any further questions.

Regards,
Ivaylo Gergov
Telerik

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Tags
Chart for XAML
Asked by
Bill
Top achievements
Rank 1
Answers by
Ivaylo Gergov
Telerik team
Share this question
or