2011-08-05 33 views
1

我有以下問題:
在我們的應用中有在運行時定義的子類別的報表列表...
報告的總體結果將顯示在一個的ColumnSeries ,它工作正常。現在,我必須在LineSeries中顯示子類別的結果以進行直接比較,這將不起作用。 這是我到目前爲止(在後面的代碼):Silverlight圖表工具包:生成供LineSeries拋出異常

foreach (var item in ReportListViewModel.ReportSections) 
{ 
    var series = new LineSeries(); 
    series.SetBinding(DataPointSeries.ItemsSourceProperty, new Binding("ItemList")); 
    series.IndependentValuePath = "Date"; 
    series.DependentValuePath = item.BindingPath; // points to an existing entry in a Dictionary<string, double> 
    series.Title = item.Text; 
    chart.Series.Add(series); 
} 

它工作正常,但一旦數據被加載時,我得到一個InvalidOperationException異常,說明密謀值沒有合適的軸被發現。

以下工作完全正常(即使它不正是我需要的):

foreach (...) 
{ 
    ... 
    series.DependentValuePath = "Result" // Result is the dependent property of the ColumnSeries, and I tested it just to make sure it isn't me 
    ... 
} 
+0

可不可以給的「item.BindingPath」的值的例子嗎? – SalvadorGomez

+0

''部分[人格]「' 正如我所說,這是一個字典<字符串,雙> {...,{」個性「,2.0},...} – Nuffin

回答

1

我不知道什麼是不同的,但現在它的工作原理...

foreach (var item in ReportListViewModel.ReportSections) 
{ 
    var series = new LineSeries(); 
    series.SetBinding(DataPointSeries.ItemsSourceProperty, new Binding("ItemList")); 
    series.IndependentValuePath = "Date"; 
    series.DependentValuePath = item.BindingPath; 
    series.Title = item.Text; 
    chart.Series.Add(series); 
} 
1

你有沒有保證,在Sections字典中ItemList的第一個項目的存在實際上是一個條目「個性」。如果沒有條目,那麼你看到的錯誤就是你會得到的。線條系列使用項目源中第一個項目的值來確定要使用的適當軸。如果該值爲空,它將會失敗,並出現與您所描述的類似的異常(您的問題中的錯誤是針對該錯誤的確切的措辭?)。