我打算獲取集合中多個項目的指定索引並填充GUI。這可以通過ObservableCollection方法完成,還是需要探索其他方法?也使用MVVM Light工具包。是否可以搜索多類型ObservableCollection的索引?
我開始用6個屬性:
ObservableCollection<Model> collection = new ObservableCollection();
Public Class Model : INotifyPropertyChanged {
private string _Item1;
public string Item1
{
get{ return _Item1;}
set{ Item1 = value; RaisedPropertyChange(nameof(Item1));
}
private int _Item2;
public int Item2
{
get{ return _Item2;}
set{ Item1 = value; RaisedPropertyChange(nameof(Item2));
}
.
.
.
.
}
作爲新MVVM,我不知道從哪裏開始就如何指定索引處得到的特定項目。我會使用LINQ方法嗎?
Where(i => i.Item1[SpecifiedIndex?]);
例子:
Output: Collection Index 1:Item1, Item2, Item3, Item4.
Output: Collection Index 2:Item1, Item2, Item3, Item4.
Output: Collection Index 3:Item1, Item2, Item3, Item4.
我卡在如何讓項目從收集的秩序。我已經添加了它們,如果我使用了一個Foreach循環,我可以返回所有項目,例如描述的輸出。但是,我不需要全部打印。我需要給定索引處的項目。
所以你只需要Item1到Item4的某些特定索引? – sachin
問題不清楚,你想要'索引'做什麼?你能替換一些有意義的變量名嗎? –