Silverlight 将字典绑定到图表

Silverlight 将字典绑定到图表,silverlight,silverlight-4.0,Silverlight,Silverlight 4.0,我是Silverlight的新手,我正在尝试用图形显示词典的内容: 在代码隐藏中: ChartData = new Dictionary<DateTime, double> {{DateTime.Now, 10}, {DateTime.Now, 20}, {DateTime.Now, 15}}; ChartData=newdictionary{{DateTime.Now,10}, {DateTime.Now,20},{DateTime.Now,15}; 在silve

我是Silverlight的新手,我正在尝试用图形显示词典的内容:

在代码隐藏中:

ChartData = new Dictionary<DateTime, double> {{DateTime.Now, 10}, 
      {DateTime.Now, 20}, {DateTime.Now, 15}};
ChartData=newdictionary{{DateTime.Now,10},
{DateTime.Now,20},{DateTime.Now,15};
在silverlight XAML中:

<toolkit:Chart HorizontalAlignment="Left" Margin="113,168,0,0" Name="chart1" 
   Title="Chart Title" VerticalAlignment="Top">
    <toolkit:LineSeries ItemsSource="{Binding Path=ChartData}"  
          DependentValuePath="Key" IndependentValuePath="Value">
    </toolkit:LineSeries>
</toolkit:Chart>

但这给出了“没有合适的轴可用于绘制相关值”。建议?

尝试以下数据集:-

ChartData = new Dictionary<DateTime, double>() { 
  { DateTime.Now.AddDays(-1), 10 }, 
  { DateTime.Now, 20 },
  { DateTime.Now.AddDays(1), 15 }
};
ChartData=newdictionary(){
{DateTime.Now.AddDays(-1),10},
{DateTime.现在,20},
{DateTime.Now.AddDays(1),15}
};
(我很惊讶您的代码行居然能工作,因为它会尝试将具有相同值的多个键添加到字典中)

然后更改您的Xaml:-

<toolkit:LineSeries ItemsSource="{Binding Path=ChartData}"    
      DependentValuePath="Value" IndependentValuePath="Key">


使用日期作为DependentValue是非常不寻常的,事实上,我想不出DependentValue除了数字之外还能做什么的场景。

一个小补充:使用
DependentValue绑定=“{Binding Path=Value}”IndependentValueBinding=“{Binding Path=Key}”
进行键/值绑定。否则它们将不起作用:)@Deruijter:这就是
xxxxx valuepath
属性最终要做的事情吗?那就是在
xxxxx valuebinding
属性上设置绑定。Anthony,既然你提到了它,我没注意到你使用了Path而不是Binding!你的方法实际上非常有效。我已经在使用
xxxxValueBinding
了,所以在阅读你的答案时,我下意识地认为你也在这样做。老实说,我不确定
xxxxValuePath
是否在屏幕后面设置
xxxxValueBinding
(我还不是xaml专家)。。但我认为很可能是这样。