0
我有以下问题:如何在可观察集合内绑定到列表中的元素?
我有一个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>
它显示多少元素是如何收集,但图表不显示任何值。 任何想法?
谢谢!
记住绑定/只适用,如果你使用的SynchronizedWithCurrentItem属性。我不知道这个图表控件,但如果它是一个ItemsControl应该有支持。 – dowhilefor
那么..我不知道它是否有,它是来自WPFToolkit库的图表。 – peer