本文整理汇总了C#中System.Collections.ObservableCollection.ForEach方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.ForEach方法的具体用法?C# ObservableCollection.ForEach怎么用?C# ObservableCollection.ForEach使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.ObservableCollection
的用法示例。
在下文中一共展示了ObservableCollection.ForEach方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ForEach_ObservableCollection
public void ForEach_ObservableCollection()
{
ObservableCollection<int> list = new ObservableCollection<int>(new int[] { 1, 2, 3, 4 }.ToList());
int result = 0;
list.ForEach<int>(i => result += i);
Assert.That(result, Is.EqualTo(10));
}
示例2: EntityQueryPagedCollectionView
// called by ObjectDataSource - set sort, grouping and filter info before calling load
internal EntityQueryPagedCollectionView(EntityQuery query, int pageSize, int loadSize,
SortDescriptionCollection sortDescriptors, ObservableCollection<GroupDescription> groupDescriptors, IPredicateDescription filter)
: this(query, pageSize, loadSize, true, false) {
sortDescriptors.ForEach(d => SortDescriptions.Add(d));
groupDescriptors.ForEach(d=> GroupDescriptions.Add(d));
SetQueryFilter(filter);
Refresh();
}
示例3: LoadView
private void LoadView() {
// Create and start loading the PCV.
// Neither EQPCV nor PCV will work with anonymous types.
if (AnonymousFns.IsAnonymousType(Query.ElementType)) {
throw new NotSupportedException("Anonymous types are not currently supported. To work around this limitation, you can instead project into a custom type.");
}
if (IsEntityQuery) {
EntityManager.GetEntityGroup(Query.ElementType).EntityChanged += ObjectDataSource_EntityChanged;
}
IsLoadingData = true;
HasChanges = false;
// Convert from our "descriptors" to the "descriptions" known by a PCV.
var sortFields = new SortDescriptionCollection();
SortDescriptors.ForEach(s => sortFields.Add(s.ToSortDescription()));
var groupFields = new ObservableCollection<GroupDescription>();
GroupDescriptors.ForEach(g => groupFields.Add(g.ToGroupDescription()));
// We'll use an EQPCV or PCV depending on a few factors: 1) an EntityQuery (so we can issue skip/take, 2) paging
bool useEqpcv = Query is EntityQuery && PageSize > 0;
if (useEqpcv) {
EntityQueryPagedCollectionView pcv = null;
var query = Query as EntityQuery;
var filter = GetQueryFilter();
if (sortFields.Count > 0 || groupFields.Count > 0) {
pcv = new EntityQueryPagedCollectionView(query, PageSize, LoadSize, sortFields, groupFields, filter);
} else {
pcv = new EntityQueryPagedCollectionView(query, PageSize, LoadSize, true, true);
pcv.SetQueryFilter(filter);
pcv.Refresh();
}
Data = pcv;
DataView = pcv;
} else {
// Use the standard PagedCollectionView (when paging isn't wanted or not an EntityQuery)
IEntityQuery query = Query;
if (Query is EntityQuery) {
query = GetFilteredQuery();
}
EntityManager.ExecuteQueryAsync(query, args => {
PagedCollectionView pcv = new PagedCollectionView(args.Results);
sortFields.ForEach(d => pcv.SortDescriptions.Add(d));
groupFields.ForEach(d => pcv.GroupDescriptions.Add(d));
pcv.PageSize = PageSize;
Data = pcv;
DataView = pcv;
});
}
}