问题
I have a Chart from Win RT Xaml Toolkit that I want to display a ColumnSeries like this:
<charting:Chart Name="columnChart" Grid.Row="1" Grid.Column="1" Width="400" Height="400">
<charting:Chart.Series>
<charting:ColumnSeries
ItemsSource="{Binding items}"
IndependentValueBinding="{Binding Name}"
DependentValueBinding="{Binding Value}"
IsSelectionEnabled="True">
</charting:ColumnSeries>
</charting:Chart.Series>
</charting:Chart>
but I always receive this error:
WinRT information: Cannot add instance of type 'WinRTXamlToolkit.Controls.DataVisualization.Charting.ColumnSeries' to a collection of type 'System.Collections.ObjectModel.Collection<WinRTXamlToolkit.Controls.DataVisualization.Charting.ISeries>'
What can be the reason for this?
回答1:
OK I found it,
The error was the ColumnSeries was missing the Title attribute, like this:
<charting:Chart Name="columnChart" Grid.Row="1" Grid.Column="1" Width="400" Height="400">
<charting:Chart.Series>
<charting:ColumnSeries
Title="Chart Title"
ItemsSource="{Binding items}"
IndependentValueBinding="{Binding Name}"
DependentValueBinding="{Binding Value}"
IsSelectionEnabled="True">
</charting:ColumnSeries>
</charting:Chart.Series>
</charting:Chart>
It seems that the Title attribute is mandatory.
来源:https://stackoverflow.com/questions/15596813/winrt-xaml-toolkit-column-series-error