In the xaml file, we can change the AxisLabelStyle by doing this:
<chartingToolkit:ColumnSeries.IndependentAxis>
<chartingToolkit:CategoryAxis Orientation="X">
<chartingToolkit:CategoryAxis.AxisLabelStyle>
<Style TargetType="chartingToolkit:AxisLabel">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="chartingToolkit:AxisLabel">
<!--some code here-->
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</chartingToolkit:CategoryAxis.AxisLabelStyle>
</chartingToolkit:CategoryAxis>
</chartingToolkit:ColumnSeries.IndependentAxis>
My question is: how to add the AxisLabelStyle in code behind?
I know we can add DataPointStyle by doing this:
ColumnSeries CS = new ColumnSeries();
CS.DataPointStyle = Application.Current.Resources["ByteBlocksColumns"] as Style;
But apparently we cannot directly change the AxisLabelStyle like this because the AxisLabelStyle is inside a CategoryAxis.
Any one can help? Thanks!
I have changed your
xaml
a little.The xaml above can be written in c# so:
And now in code-behind you can set the
AxisLabelStyle
property in this way:Don't forget to cast the
IndependentAxis
property to a correct type, because by default it has theIAxis
type which doesn't have a label style.