【发布时间】:2017-05-09 02:34:26
【问题描述】:
我计划获取集合中多个项目的指定索引并填充 GUI。这可以通过 ObservableCollection 方法完成,还是需要探索其他方法?还使用 MVVM Light 工具包。
我从 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?
-
问题不清楚,你想让'index'做什么?你能用一些有意义的变量名来代替吗?
标签: c# wpf linq mvvm mvvm-light