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

Welcome to the SciChart Community Forums!

Please use the forums below to ask questions about SciChart. Take a moment to read our Question asking guidelines on how to ask a good question and our support policy

We also have a tag=SciChart on where you can earn rep for your questions!


Depending on the Size of my control which has the scichart on it, I want to change the FontSize of the Axis-Tick-Labels.

In XAML I defined a style

 <Style x:Key="XAxisLabelStyle" TargetType="s:DefaultTickLabel">
        <Setter Property="Foreground" Value="Black"/>
        <Setter Property="FontSize" Value="{Binding AxisFontSize}"/>
        <!-- Align labels to the left side by using the AnchorPoint (docking point) on the right -->
        <Setter Property="HorizontalAnchorPoint" Value="Left"/>

and use it for the chart axis:

            <s:NumericAxis Name="XAxis" AxisTitle="m/z" TitleStyle="{StaticResource AxisLabelStyle}" TickLabelStyle="{StaticResource XAxisLabelStyle}">
                    <s:DoubleRange Min="0" Max="20000" />

I have a binding to a property (AxisFontSize) which I can set from outside the control. For the axis label it works fine. But the TickLabels don’t change the FontSize. What have I to do?

  • You must to post comments

I see you’ve already found our article on Adding Color to a NumericAxis (styling the axis).

What are you binding to? Check if there are any binding errors in the output window.

I believe the DataContext of DefaultTickLabel is DefaultTickLabelViewModel. You may need to specify a RelativeSource binding to walk up the VisualTree from DefaultTickLabel to Axis, such as:

<!-- Warning: Untested! -->
<Style x:Key="XAxisLabelStyle" TargetType="s:DefaultTickLabel">

        <!-- Assumes Axis DataContext is a view model with property AxisFontSize -->
        <Setter Property="FontSize" Value="{Binding DataContext.AxisFontSize, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type s:AxisBase}}}"/>


Try it, let me know if it works.

Best regards,

  • Michael Knitsch
    It nearly works. Here is a picture: From the eight chart the rest of the charts have a strange behavior. They change the fontsize very fast between the small and the standard font.In the output-window I get the following error: System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='Abt.Controls.SciChart.Visuals.Axes.AxisBase', AncestorLevel='1''. BindingExpression:Path=DataContext.AxisFontSize; DataItem=null; target element is 'NumericTickLabel' (Name=''); target property is 'FontSize' (type 'Double')I am very new to work with WPF and XAML Bindings!In my control which contains the SciChart I have a Property for the Axis-Font public double AxisFontSize { get { return _axisFontSize; } set { if (!_axisFontSize.Equals(value)) { _axisFontSize = value; OnPropertyChanged("AxisFontSize"); } } } private double _axisFontSize; The control inherits from INotifyPropertyChanged to make the binding possible. In the Mainprogram I create the SciCharts in a loop (I change the FontSize only, if there are a specific number of charts to create): var specView = new SpectrumViewSmall(); specView.AxisFontSize = 4; In the control I set DataContext = this in the constructor.
  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.