Hi,
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,
}
}
}
};
- Jonathan Janesjö asked 7 years ago
- You must login 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" />
</Style>
Hope this helps!
Best regards,
Yuriy
- Yuriy Zadereckiy answered 7 years ago
- You must login 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:
- Let the user pick the output size of the graph.
- Change the fontsize of the legent accordingly.
- Save the snapshot.
- Reset the fontsize to the original one.
Thanks,
Daniel
- Jonathan Janesjö answered 7 years ago
- You must login to post comments
Please login first to submit.