I'm having trouble styling the LegendItem's which are automatically added to the Legend control once the series are bound to the DataChart.
All I want to do is add a button to the LegendItemTemplate. When I style the LegendItem through Blend and when remove the x:Key for the style, which should mean the style is applied globally across the current view, nothing happens.
Can someone please advise how to template the LegendItem? I've read the documentation but it's pretty brief and doesn't really tell you anything.
Hi,
The easiest way to restyle the legend item appearance is to provide an alternate DataTemplate for the legend item. You can do this by setting the LegendItemTemplate on the series. For reference, this is the default DataTemplate that is used for the legend items:
<DataTemplate x:Key="LegendItemTemplate"/> <StackPanel Orientation="Horizontal" Margin="1" Visibility="{Binding Series.Visibility}"> <ContentPresenter Content="{Binding}" ContentTemplate="{Binding Series.LegendItemBadgeTemplate}" /> <ContentPresenter Content="{Binding Series.Title, TargetNullValue=Series Title}"/> </StackPanel> </DataTemplate>
You will also see there how the default template references the LegendItemBadgeTemplate on the owning series. This is how you get the little badge that matches the series appearance in the legend item. You can also replace this badge by setting the appropriate property on the Series.
Hope this helps!
-Graham
Brilliant, I was really close. I just couldn't find an example of the DataTemplate. Thanks so much for the quick response.