Pre loader

Cannot access series color when creating LegendModifier.LegendItemTemplate

Welcome to the SciChart Forums!

  • Please read our Question Asking Guidelines for how to format a good question
  • Some reputation is required to post answers. Get up-voted to avoid the spam filter!
  • We welcome community answers and upvotes. Every Q&A improves SciChart for everyone

WPF Forums | JavaScript Forums | Android Forums | iOS Forums


I spent all day on this one and was reluctant to ask but despite all my efforts here I am asking this question in the forum. This started with an undesirable behavior when showing/hiding the point markers on my series. When my series is being displayed on the legend AFTER the legend is already visible the point marker is “sort of displayed”, meaning you can see a small missing piece of the series line in the legend as if a point marker is there. But, it is not. If I select another series on my chart after I have elected to show the legend and point markers this problem doesn’t exist. I’d prefer not to get into the depths of the view model for which I am binding my series to the SciChart and instead focus on why I am unable to access information in the s:SeriesInfo that I assume should be available.

Basically I want to build my own custom legend and it’s simply not working as I would expect. The only thing that is binding with success is the SeriesName. See the following example.

<DataTemplate DataType="{x:Type s:SeriesInfo}">
    <StackPanel Orientation="Horizontal">

        <Rectangle Height="2" Width="120" Fill="{Binding RenderableSeries.Stroke}" />

        <Ellipse Width="10" Height="10">
                <Style TargetType="{x:Type Ellipse}">
                    <Setter Property="Stroke" Value="{Binding RenderableSeries.Stroke}" />
                    <Setter Property="Fill" Value="{Binding RenderableSeries.PointMarker.Fill}" />
                    <Setter Property="StrokeThickness" Value="1" />
                    <Setter Property="Margin" Value="10,0,10,0" />
                    <Setter Property="Visibility" Value="Visible" />
                        <DataTrigger Binding="{Binding Path=ShowPoints, Mode=TwoWay}" Value="True">
                            <Setter Property="Visibility" Value="Visible" />

        <TextBlock Text="{Binding RenderableSeries.DataSeries.SeriesName}" />


Nothing. Despite reading pages and articles/posts on SciChart’s website I have run into a wall and decided to ask for help.

  • You must to post comments
Best Answer

Hi Chris,

I think this might be a converter issue.

I can share with you our LegendItemTemplate in the SciChart library to explain why.

<DataTemplate x:Key="SciChartLegendItemTemplate" DataType="chartData:SeriesInfo">
    <StackPanel Orientation="Horizontal">
        <CheckBox Margin="5,0,0,0"
                  IsChecked="{Binding RenderableSeries.IsVisible, Mode=TwoWay}"
                  Visibility="{Binding LegendData.ShowVisibilityCheckboxes, RelativeSource={RelativeSource AncestorType=visuals:SciChartLegend}, Converter={StaticResource BooleanToVisibilityConverter}}" />

        <r:PointMarker Width="40"
                       DataContext="{Binding RenderableSeries}"
                       DeferredContent="{Binding LegendMarkerTemplate}"
                       Visibility="{Binding ShowSeriesMarkers, RelativeSource={RelativeSource AncestorType=visuals:SciChartLegend}, Converter={StaticResource BooleanToVisibilityConverter}}" />

        <TextBlock Margin="5,0,5,0"
                   Text="{Binding SeriesName}" 
                   Foreground="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=r:LegendPlaceholder}, Path=Foreground}"/>

Notice PointMarker above. The LegendMarkerTemplate is defined on the series itself which is why PointMarker.DataContext is set to the RenderableSeries.

The standard template is

<DataTemplate x:Key="DefaultLegendMarkerTemplate" DataType="r:BaseRenderableSeries">
        Stroke="{Binding Stroke, Converter={StaticResource ColorToBrushConverter}}"
        Y2="0.5" />

RenderableSeries.Stroke is Color whereas Line.Stroke expects Brush. So we are using ColorToBrushConverter. This is defined in the SciChart.Charting.Common.Databinding namespace.

Perhaps try that?

Second suggestion is check for binding errors in the output window.

Best regards,

  • Chris Kirkman
    I’m trying this right now.
  • Chris Kirkman
    I kept getting an exception in the output window indicating that it was an unauthorized class. I just created my own value converter class and it works now. :) Thanks for the help.
  • Andrew Burnett-Thompson
    nice! Glad to be of help!
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.