如何设置 ColumnSeries 的 ItemsSource 值?

How to set ItemsSource value of ColumnSeries?

我无法设置 ColumnSeriesItemsSource 值。我正在关注一些示例 (this and this),但它们似乎已过时。

这是我的 XAML:

<Charting:Chart x:Name="ColumnChart"
                HorizontalAlignment="Center"
                VerticalAlignment="Center"
                Width="Auto"
                Height="Auto">
    <Charting:ColumnSeries Title="Georgi Kyuchukov"
                           Margin="0"
                           Name="ColumnChartSeries"
                           IndependentValuePath="Name"
                           DependentValuePath="Pts"
                           IsSelectionEnabled="True" />
</Charting:Chart>

这是我的 C# 代码:

public class ChartData
{
    public string Name { get; set; }
    public int Pts { get; set; }
}

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    List<ChartData> personalData = (List<ChartData>)e.Parameter;

    foreach (ChartData x in personalData){
        Debug.WriteLine(x.Name + " " + x.Pts);
    }

    (ColumnChart.Series[0] as ColumnSeries).ItemsSource = personalData;
    //ColumnChartSeries.ItemsSource = personalData;
}

我收到以下错误:

Error 1 The type or namespace name 'ColumnSeries' could not be found (are you missing a using directive or an assembly reference?)

我也试过了:

ColumnChartSeries.ItemsSource = personalData;

但是得到:

An exception of type 'System.NullReferenceException' occurred in gotqn.exe but was not handled in user code.

此外,我经常遇到以下错误:

Error 1 A value of type 'ColumnSeries' cannot be added to a collection or dictionary of type 'Collection`1'.

但我可以运行申请,所以我想这并不重要。

你能告诉我哪里做错了吗?

另外,如果能给我一些很好的最新文档,我将不胜感激 link/article。

也许您在后面的代码中遗漏了这个...

using WinRTXamlToolkit.Controls.DataVisualization.Charting;

尝试将光标移动到 ColumnSeries,然后按 Alt+Shift+F10 添加缺少的命名空间。或者,如果您有 ReSharper(我推荐),只需使用 Alt+Enter。