具有WPF Toolkit异常的ColumnSeries绑定数据
本文关键字:ColumnSeries 绑定 数据 异常 WPF Toolkit 具有 | 更新日期: 2023-09-27 18:25:08
我使用WPF Toolkit
扩展来显示从Dictionary<string,ulong>
获取数据的Column Graph(其中字符串是X值,ulong是Y值)。这是XAML 的声明
<chartingToolkit:Chart x:Name="Chart" HorizontalAlignment="Left" Margin="10,10,0,0" Title="Chart Title" VerticalAlignment="Top" Height="560" Width="1000">
<chartingToolkit:ColumnSeries x:Name="myGraph" DependentValuePath="Key" IndependentValuePath="Value" ItemsSource="{Binding}"/>
</chartingToolkit:Chart>
我有一个构建Dictionary <string,ulong>
的对象
因此,我声明了全局变量
private Dictionary<string,ulong> myDictionary;
存储来自我的对象的数据,并将其与图表绑定,如下所示
this.myDictionary = myObject.objectDictionary;
myGraph.Title = "My Title";
myGraph.ItemsSource = this.myDictionary;
但我得到了以下例外:
Object reference not set to an instance of an object.
那么,我的装订有错吗?
问候
好的,我在程序中发现了错误。我没有使用ItemsSource
,而是使用了正确定义IndependentValuePath
和DependentValuePath
的myGraph.DataContext
。
this.myDictionary = myObject.objectDictionary;
myGraph.DataContext = this.myDictionary;
myGraph.IndependentValuePath = "Key";
myGraph.DependentValuePath = "Value";