本文整理汇总了C#中System.Collections.ObservableCollection.WithUpdates方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollection.WithUpdates方法的具体用法?C# ObservableCollection.WithUpdates怎么用?C# ObservableCollection.WithUpdates使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Collections.ObservableCollection
的用法示例。
在下文中一共展示了ObservableCollection.WithUpdates方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GroupBy_ObservableSourceItemAdded_Update
public void GroupBy_ObservableSourceItemAdded_Update()
{
var update = false;
ICollection<Dummy<string>> coll = new ObservableCollection<Dummy<string>>();
var test = coll.WithUpdates().GroupBy(d => d.Item);
test.CollectionChanged += (o, e) =>
{
Assert.IsTrue(ContainsGroup(e.NewItems, "42"));
Assert.AreEqual(1, e.NewItems.Count);
update = true;
};
Assert.IsTrue(!test.Any());
Assert.IsFalse(update);
coll.Add(new Dummy<string>() { Item = "42" });
Assert.IsFalse(!test.Any());
Assert.IsTrue(Sys.Any(test, group => group.Key == "42"));
Assert.IsTrue(update);
}
示例2: GroupBy_ObservableKeyChangesBetweenGroups_Update
public void GroupBy_ObservableKeyChangesBetweenGroups_Update()
{
var updateGroups = false;
var updateGroupA = false;
var updateGroupB = false;
ICollection<Dummy<string>> coll = new ObservableCollection<Dummy<string>>();
var dummy1 = new Dummy<string>("A");
var dummy2 = new Dummy<string>("B");
var dummyChange = new ObservableDummy<string>("A");
coll.Add(dummy1);
coll.Add(dummy2);
coll.Add(dummyChange);
var test = coll.WithUpdates().GroupBy(d => d.Item);
test.CollectionChanged += (o, e) => updateGroups = true;
var groupA = Sys.Single(test, g => g.Key == "A") as ObservableGroup<string, Dummy<string>>;
var groupB = Sys.Single(test, g => g.Key == "B") as ObservableGroup<string, Dummy<string>>;
Assert.IsNotNull(groupA);
Assert.IsNotNull(groupB);
Assert.IsTrue(Sys.Contains(groupA, dummy1));
Assert.IsTrue(Sys.Contains(groupA, dummyChange));
Assert.IsTrue(Sys.Contains(groupB, dummy2));
Assert.IsFalse(updateGroups);
var notifierA = groupA as INotifyCollectionChanged;
var notifierB = groupB as INotifyCollectionChanged;
Assert.IsNotNull(notifierA);
Assert.IsNotNull(notifierB);
notifierA.CollectionChanged += (o, e) =>
{
Assert.IsTrue(e.OldItems.Contains(dummyChange));
updateGroupA = true;
};
notifierB.CollectionChanged += (o, e) =>
{
Assert.IsTrue(e.NewItems.Contains(dummyChange));
updateGroupB = true;
};
dummyChange.Item = "B";
Assert.IsFalse(updateGroups);
Assert.IsTrue(updateGroupA);
Assert.IsTrue(updateGroupB);
Assert.IsTrue(Sys.Contains(groupA, dummy1));
Assert.IsTrue(Sys.Contains(groupB, dummy2));
Assert.IsTrue(Sys.Contains(groupB, dummyChange));
}
示例3: GroupBy_NoObservableKeyChangesEraseGroup_NoUpdate
public void GroupBy_NoObservableKeyChangesEraseGroup_NoUpdate()
{
var update = false;
ICollection<Dummy<string>> coll = new ObservableCollection<Dummy<string>>();
var dummy1 = new Dummy<string>("A");
var dummy2 = new Dummy<string>("B");
coll.Add(dummy1);
coll.Add(dummy2);
var test = coll.WithUpdates().GroupBy(d => d.Item);
test.CollectionChanged += (o, e) => update = true;
Assert.IsTrue(Sys.Contains(Sys.First(test, group => group.Key == "A"), dummy1));
Assert.IsTrue(Sys.Contains(Sys.First(test, group => group.Key == "B"), dummy2));
Assert.IsFalse(update);
dummy2.Item = "A";
Assert.IsFalse(update);
}
示例4: GroupBy_ObservableKeyChangesEraseGroup_Update
public void GroupBy_ObservableKeyChangesEraseGroup_Update()
{
var update = false;
ICollection<Dummy<string>> coll = new ObservableCollection<Dummy<string>>();
var dummy1 = new Dummy<string>("A");
var dummy2 = new ObservableDummy<string>("B");
coll.Add(dummy1);
coll.Add(dummy2);
var test = coll.WithUpdates().GroupBy(d => d.Item);
test.CollectionChanged += (o, e) =>
{
Assert.IsTrue(ContainsGroup(e.OldItems, "B"));
update = true;
};
Assert.IsTrue(Sys.Contains(Sys.Single(test, group => group.Key == "A"), dummy1));
Assert.IsTrue(Sys.Contains(Sys.Single(test, group => group.Key == "B"), dummy2));
Assert.IsFalse(update);
dummy2.Item = "A";
Assert.IsTrue(update);
Assert.AreEqual(1, test.Count());
Assert.IsTrue(Sys.Contains(Sys.Single(test, group => group.Key == "A"), dummy2));
}
示例5: GroupBy_NoObservableKeyChangesToNewGroup_NoUpdate
public void GroupBy_NoObservableKeyChangesToNewGroup_NoUpdate()
{
var update = false;
ICollection<Dummy<string>> coll = new ObservableCollection<Dummy<string>>();
var dummy1 = new Dummy<string>("A");
var dummy2 = new Dummy<string>("A");
coll.Add(dummy1);
coll.Add(dummy2);
var test = coll.WithUpdates().GroupBy(d => d.Item);
test.CollectionChanged += (o, e) => update = true;
var group = Sys.Single(test);
Assert.IsTrue(Sys.Contains(group, dummy1));
Assert.IsTrue(Sys.Contains(group, dummy2));
Assert.IsFalse(update);
dummy2.Item = "B";
Assert.IsFalse(update);
}