Deborah's Developer MindScape

         Tips and Techniques for Web and .NET developers.

January 29, 2011

Missing Chart Legend

Filed under: C#,Silverlight,VB.NET @ 7:18 pm

If you built a custom theme for your application (similar to this prior post) then you may find that your chart legend contents disappear.

NOTE: This post is part of a series that starts with this prior post. The example in this post uses the application that is built as part of that series.

The chart built in this prior post looks like this:


Notice that the legend (circled in red) is empty.

The problem appears to be a mismatch between the standard theme dll (which displays the legend correctly) and the theme source file provided for customization (which does not display the legend correctly).

To fix the legend:

1)  Find the visualizationToolkit:Legend Style in your theme.

2) Replace the StackPanel in the theme file with an ItemsPresenter.

3) Rebuild the solution.

The legend then magically appears:


You can then set other style properties, such as the size and font, to improve the look of the legend.


The resulting style is shown below with the modified lines shown in red.

<Style TargetType="visualizationToolkit:Legend">
    <Setter Property="BorderBrush"
     Value="{StaticResource ControlBorderBrush}"/>
    <Setter Property="Background"
     Value="{StaticResource ControlBackgroundBrush}"/>
    <Setter Property="Foreground" Value="Black"/>
    <Setter Property="BorderThickness" Value="1"/>
    <Setter Property="IsTabStop" Value="False"/>
    <Setter Property="TitleStyle">
            <Style TargetType="visualizationToolkit:Title">
                <Setter Property="Margin" Value="0,5,0,10"/>
                <Setter Property="FontWeight" Value="Bold"/>
                <Setter Property="HorizontalAlignment" Value="Center"/>
    <Setter Property="Template">
            <ControlTemplate TargetType="visualizationToolkit:Legend">
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                            <RowDefinition Height="Auto"/>
                            Content="{TemplateBinding Header}"
                            Style="{TemplateBinding TitleStyle}"/>
                                Margin="10,0,10,10" />

If you use the same custom theme for your entire application, you will only need to do this one time. If you use multiple custom themes, you will need to repeat this process for each theme file.


RSS feed for comments on this post. TrackBack URI

Leave a comment

© 2023 Deborah's Developer MindScape   Provided by WPMU DEV -The WordPress Experts   Hosted by Microsoft MVPs