wp7 ObservableCollection人口

时间:2011-12-05 02:28:11

标签: windows-phone-7.1 windows-phone-7

我正在使用AMCharts控件,但我试图按照这个例子,但我不确定如何将我的historyItemCollection(图1)中的数据导入Observable集合(图2)?

图1:

from item in App.ViewModel.historyItemCollection
where item.VehicleId == (Application.Current as App).vehicleId
select item;

图2:

private ObservableCollection<TestDataItem> _data = new ObservableCollection<TestDataItem>()
{
    new TestDataItem() { axis = "Mar", value=5},
    new TestDataItem() { axis = "Apr", value=15.2},
    new TestDataItem() { axis = "May", value=25},
    new TestDataItem() { axis = "June", value=8.1},
};

在historyitemcollection中,我有一个日期项目,我将放在轴值中,以及我将放入值值的成本项目(图2 :)

如何将我的数据导入observableCollection以便我可以使用此图表控件?

1 个答案:

答案 0 :(得分:1)

_data = new ObservableCollection<HistoryItem>
(
    from item in App.ViewModel.historyItemCollection
    where item.VehicleId == (Application.Current as App).vehicleId
    select item;
)

或者如果在运行时

var historyItems =
    from item in App.ViewModel.historyItemCollection
    where item.VehicleId == (Application.Current as App).vehicleId
    select item;

foreach (var item in historyItems)
    _data.Add(item);