I am using the WPF Toolkit (System.Windows.Controls.DataVisualization.Toolkit) to generate a simple chart. In order to set my Y-axis to start from a value of zero, I set the Chart.Axes property like so:
<chartingToolkit:Chart Width="800" Height="400" Title="Usage" Style="{StaticResource ChartStyle}">
<chartingToolkit:Chart.Axes>
<chartingToolkit:LinearAxis Orientation="Y" Minimum="0" />
</chartingToolkit:Chart.Axes>
<chartingToolkit:LineSeries DependentValuePath="Value" IndependentValuePath="Key" ItemsSource="{Binding Data}" />
</chartingToolkit:Chart>
This works fine. However, when I try to set this property through a Style, intellisense does not even show Axes.
<Style x:Key="ChartStyle" TargetType="{x:Type chartingToolkit:Chart}">
<Setter Property="Axes">
<Setter.Value>
<chartingToolkit:LinearAxis Orientation="Y" Minimum="0" />
</Setter.Value>
</Setter>
</Style>
If I run the code, I get an ArgumentNullException saying Property cannot be null. This is Style.Setter.Property. I looked into the source code at Codeplex and found the Axes property:
[SuppressMessage("Microsoft.Usage", "CA2227:CollectionPropertiesShouldBeReadOnly", Justification = "Setter is public to work around a limitation with the XAML editing tools.")]
[SuppressMessage("Microsoft.Usage", "CA1801:ReviewUnusedParameters", MessageId = "value", Justification = "Setter is public to work around a limitation with the XAML editing tools.")]
public Collection<IAxis> Axes
{
get
{
return _axes;
}
set
{
throw new NotSupportedException(Properties.Resources.Chart_Axes_SetterNotSupported);
}
}
It says here that Setter is public but I cannot find any such public method. Now my questions are:
- How is setting the property through a Style technically different from the first block of code in this question?
- Is there a way I can set the
Axesproperty through a Style? - Should I still be using the WPF Toolkit for charts? Is there a newer "canon" method to generate charts that I am not aware of?