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 Stackoverflow.com where you can earn rep for your questions!

Please note: SciChart team will only answer questions from customers with active support subscriptions. Expired support questions will be ignored. If your support status shows incorrectly, contact us and we will be glad to help.

1
0

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"/>
 </Style>

and use it for the chart axis:

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

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
0
0

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}}}"/>

 </Style>

Try it, let me know if it works.

Best regards,
Andrew

  • Michael Knitsch
    It nearly works. Here is a picture: http://up.picr.de/20158066fg.jpg 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.