ハードコードされたテスト データを返すビュー モデルのプロパティがあります。
public ObservableCollection<Item> Items
{
get
{
return new ObservableCollection<Item> {
new Item { Key = 0, Count = 5 },
new Item { Key = 1, Count = 3 },
new Item { Key = 2, Count = 2 },
new Item { Key = 3, Count = 7 }
}
}
}
私のチャートは、ビューで次のように定義されています。
<toolkit:WrapPanel>
<toolkit:Chart>
<toolkit:LineSeries ItemsSource="{Binding Items}" IndependentAxis="{Binding Key}" DependentValueBinding="{Binding Count}"/>
</toolkit:Chart>
</toolkit:WrapPanel>
そのコードでは、次の例外が発生します。
System.Windows.Data Error: BindingExpression path error: 'Key' property not found on 'Test.MyViewModel' 'Test.MyViewModel' (HashCode=50157845). BindingExpression: Path='Key' DataItem='Test.MyViewModel' (HashCode=50157845); target element is 'System.Windows.Controls.DataVisualization.Charting.LineSeries' (Name=''); target property is 'IndependentAxis' (type 'System.Windows.Controls.DataVisualization.Charting.IAxis').
DataContext
チャートの をにバインドするとItems
、例外はスローされませんが、チャートにはデータが表示されません。
編集: いいえ、代わりにコレクションに Key と Count をバインドできないと文句を言います。
私が見たすべての例では、チャートがこのように設定されているのに、なぜビュー モデルにバインドしようとしているのですか? というか、なぜこれが他の人にも効果があるように見えるのでしょうか?