次の問題があります。
モデルとして ObservableCollection があります。これは次のようになります。
public class HistoryViewModel : ViewModelBase
{
private ObservableCollection<List<KeyValuePair<DateTime, float>>> _valuePairs;
public ObservableCollection<List<KeyValuePair<DateTime, float>>> ValuePairs
{
get
{
return this._valuePairs;
}
set
{
this._valuePairs= (ObservableCollection<List<KeyValuePair<DateTime, float>>>)value;
OnPropertyChanged("ValuePairs");
}
}
}
ご覧のとおり、このコレクションはリストで構成されているため、リスト内の KeyValuePair にバインドする必要があります。しかし、方法がわかりません。問題は、コレクションにもリストにも含まれるアイテムの数がわからないことです。
私の試みは今次のようになります:
<ItemsControl ItemsSource="{Binding Path=ValuePairs}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel></StackPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<charting:Chart Width="400" Height="250">
<charting:Chart.Series>
<charting:LineSeries Title="Monthly Count"
IndependentValueBinding="{Binding //, Path=Key}"
DependentValueBinding="{Binding //, Path=Value}">
</charting:LineSeries>
</charting:Chart.Series>
</charting:Chart>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
コレクション内の要素の数が表示されますが、グラフには値が表示されません。何か案は?
ありがとう!