Altering Legend Styles

If you dont like how each individual legend piece is styled, or want to develop your own chart pieces, you can create new styles and link them to the series via the SeriesLegendStyle Property.

The legend pieces are defined by a style of Target Type ChartLegendItem. The <controlTemplate> should be set as in the example below.

The following properties are available to bind to
Caption The title for the series
ItemBrush The pallette colour of the series
GADataPointStyle The style associated with the datapoint

and those inherited from ContentControl (ie FontSize etc)

Example 1 - the base scatter piece legend
A rectangle of the same style of the datapoint, with a textblock showing the caption of the series, wrapped in a horizontal stack panel.

<Style x:Key="GAScatterPieceLegendStyle" TargetType="GAGraph:ChartLegendItem">
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="VerticalContentAlignment" Value="Top" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="GAGraph:ChartLegendItem">
                    <StackPanel Orientation="Horizontal" Margin="0 0 10 5">
                        <Rectangle Style="{Binding DataPointStyle}"  Margin="0 0 5 0" />
                        <TextBlock FontSize="{TemplateBinding FontSize}" VerticalAlignment="Center" Text="{TemplateBinding Caption}"></TextBlock>
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

Example 2 - the default line piece legend
A line of the same style of the datapoint, with a textblock showing the caption of the series, wrapped in a horizontal stack panel.

    <Style x:Key="GALinePieceLegendStyle" TargetType="GAGraph:ChartLegendItem">
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="VerticalContentAlignment" Value="Top" />
        <Setter Property="IsTabStop" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="GAGraph:ChartLegendItem">
                    <StackPanel Orientation="Horizontal" Margin="0 0 10 5">
                        <Path Style="{Binding DataPointStyle}" Margin="0 0 5 0">
                            <Path.Data>
                                <LineGeometry>
                                    <LineGeometry.StartPoint>
                                        <Point X="0" Y="8"></Point>
                                    </LineGeometry.StartPoint>
                                    <LineGeometry.EndPoint>
                                        <Point X="20" Y="8"></Point>
                                    </LineGeometry.EndPoint>
                                </LineGeometry>
                            </Path.Data>
                        </Path>
                        <TextBlock FontSize="{TemplateBinding FontSize}" VerticalAlignment="Center" Text="{TemplateBinding Caption}"></TextBlock>
                    </StackPanel>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

Last edited Oct 8, 2015 at 2:27 AM by gravityapps, version 1