SciChart® the market leader in Fast WPF Charts, WPF 3D Charts, and iOS Chart & Android Chart Components


I am trying to color the lines inside the chart of the major grid lines with:

<Setter Property="MajorGridLineStyle">
    <Style TargetType="Line">
       <Setter Property="Stroke" Value="{Binding XAxis.TickTextBrush}"/>
       <Setter Property="StrokeThickness" Value="1"/>

But with this code they vanish completely. I have seen the sample for xaml styling. There are 2 other options:
One is StrockDashArray, but I don’t want a dashed line. I just want the line. (But this works).
And there is another sample setting Y2 and X2. But I don’t understand that. It has no effect for me (still no lines). Looking at the documentation it says these are the points where the line ends. But I don’t know where the line should end.

How can I style the major grid lines (or minor grid lines)?

  • You must to post comments
Best Answer

I coded the following behavior which seems to work for me. Even if the grid is showing data. And without calling InvalidateElement on sciChartSurface.

internal class GridLineColorBehavior
    /// <summary>
    /// Defines the gridlinestyle
    /// </summary>
    public static readonly DependencyProperty GridLineStyleProperty = DependencyProperty.RegisterAttached(
        "GridLineColor", typeof(Color), typeof(GridLineColorBehavior), new PropertyMetadata(default(Color), OnGridLineColorChanged));

    private static void OnGridLineColorChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
        NumericAxis numericAxis = d as NumericAxis;
        if (numericAxis == null)
            throw new ArgumentException("unexpected object", "d");
        if (e.NewValue is Color)

            Style newStyle = new Style(typeof(Line));
            newStyle.Setters.Add(new Setter(Line.StrokeProperty, new SolidColorBrush((Color)e.NewValue)));
            numericAxis.MajorGridLineStyle = newStyle;

    public static void SetGridLineColor(DependencyObject element, Color value)
        element.SetValue(GridLineStyleProperty, value);

    public static Color GetGridLineColor(DependencyObject element)
        return (Color)element.GetValue(GridLineStyleProperty);


And in XAML:

<Style x:Key="YAxisStyle" TargetType="sciChart:AxisBase">
    <Setter Property="ui:GridLineColorBehavior.GridLineColor" Value="{Binding Color}"/>

Everytime I change the color then the color of the gridlines get changed as well. It seems even in the middle while appending data.

  • You must to post comments

If you replace this line

<Setter Property="Stroke" Value="{Binding XAxis.TickTextBrush}"/>

with this

<Setter Property="Stroke" Value="Red"/>

What happens? I’m guessing a red gridline (as per our styling axis gridlines KB article).

If so, then its likely the binding is not working. Why? because internally to SciChart we do not use WPF lines, we simply extract the properties from a style to apply to our own bitmap renderer. This is part of the reason why SciChart is so fast – we don’t use WPF for the drawing.

So a binding to XAxis.TickTextBrush won’t work. Instead you’re going to need to set it to a hard-coded color in the style.

Let me know if this helps,


  • Uwe Hafner
    I read about the bitmapping but somehow it did not diffuse to my brain that I won't be able to set the stroke color as well. :(. Could I somehow reset "something" "somehow". Setting this color could only be a user setting which can be set in the application settings and does not need to be "on the fly". I could recreate or reset almost everything of scichart on this change. I just would like to use a property of my settings. Its only on my xAxis because I change the color of everything else as well and the lines then would have the same color as the numbers and title.
  • Andrew Burnett-Thompson
    You can try swapping out the style for a new instance. This will force the bitmap engine to pick up the new colour. Or, you can try binding to a static property and after updating it call Scichartsurface.Invalidateelement to force a redraw
  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.