Pre loader

Can the FontSize of a LegendModifier be changed programmatically?

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



How can I change the fontsize of a LegendModifier programmatically? By trying the code below changes the backgound color but not the font size:

var style = new Style(typeof(LegendModifier));
style.Setters.Add(new Setter(Control.BackgroundProperty, Brushes.DarkSlateGray));
style.Setters.Add(new Setter(Control.FontSizeProperty, 34d));
MainChart = new SciChartSurface
    HorizontalAlignment = HorizontalAlignment.Stretch,
    VerticalAlignment = VerticalAlignment.Stretch,
    Padding = new Thickness(30,20,16,0),
    Background = new SolidColorBrush(Color.FromRgb(32,32,33)),
    YAxis = new NumericAxis(),
    ChartModifier = new ModifierGroup
        ChildModifiers = new ObservableCollection<IChartModifier>
            new LegendModifier
                Margin = new Thickness(10),
                VerticalAlignment = VerticalAlignment.Top,
                GetLegendDataFor = SourceMode.AllSeries,
                LegendPlacement = LegendPlacement.Inside,
                ShowLegend = true,
                ShowVisibilityCheckboxes = true,
                Style = style,
  • You must to post comments

Hi Daniel,

Thanks for your question. To change FontSize for a Legend, you need to set a property on a legend control itself, not on a LegendModifier. LegendModifier creates a SciChartLegend control internally and provides an API to access and change properties on it to some degree. Here is a relevant documentation article, where you can find more info about how it works.

So to have an impact on a legend control itself, you can add an implicit style for SciChartLegend. The value then will be propagated down the VisualTree to legend items:

    <Style TargetType="s:SciChartLegend">
        <Setter Property="FontSize" Value="5" />

Hope this helps!

Best regards,

  • You must to post comments

Thanks Yuriy,

That works great as a global override, but how would I do it programmatically?

I need to change (temporarily) the fontsize of the Legends of my graph before saving a snapshot of it depending on the output size of the graph. (The bigger the graph, the bigger the text in the legends). Ideally I’d need to:

  1. Let the user pick the output size of the graph.
  2. Change the fontsize of the legent accordingly.
  3. Save the snapshot.
  4. Reset the fontsize to the original one.


  • You must to post comments
Showing 2 results
Your Answer

Please first to submit.