本文整理汇总了C#中ObservableCollectionEx.ClearAndAddRange方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableCollectionEx.ClearAndAddRange方法的具体用法?C# ObservableCollectionEx.ClearAndAddRange怎么用?C# ObservableCollectionEx.ClearAndAddRange使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableCollectionEx
的用法示例。
在下文中一共展示了ObservableCollectionEx.ClearAndAddRange方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ClearAddRangeDoesntRaiseAnEventIfNothingIsAddedOrCleared
public void ClearAddRangeDoesntRaiseAnEventIfNothingIsAddedOrCleared()
{
var oc = new ObservableCollectionEx<string>();
var toAdd = new List<string>();
oc.MonitorEvents();
oc.ClearAndAddRange(toAdd);
oc.ShouldNotRaise("CollectionChanged");
}
示例2: ClearAndAddRangeWithANullCollectionThrows
public void ClearAndAddRangeWithANullCollectionThrows()
{
var oc = new ObservableCollectionEx<string>();
oc.ClearAndAddRange(null);
}
示例3: ClearAndAddRangeOnlyRaisesOneRemoveCollectionChangedEventAtTheEndIfNoItemsAreAddedAndSomeAreCleared
public void ClearAndAddRangeOnlyRaisesOneRemoveCollectionChangedEventAtTheEndIfNoItemsAreAddedAndSomeAreCleared()
{
var oc = new ObservableCollectionEx<string>
{
"Foo",
"Bar"
};
var toAdd = new List<string>();
var itemCount = 0;
var eventCount = 0;
var action = NotifyCollectionChangedAction.Add;
IList<string> removedItems = null;
oc.CollectionChanged += (sender, args) =>
{
++eventCount;
itemCount = oc.Count;
action = args.Action;
removedItems = args.OldItems.OfType<string>().ToList();
};
oc.ClearAndAddRange(toAdd);
itemCount.Should().Be(0);
eventCount.Should().Be(1);
action.Should().Be(NotifyCollectionChangedAction.Remove);
removedItems.ShouldBeEquivalentTo(new List<string>
{
"Foo",
"Bar"
});
}
示例4: ClearAndAddRangeOnlyRaisesOneResetCollectionChangedEventAtTheEndIfItemsAreClearedAndAdded
public void ClearAndAddRangeOnlyRaisesOneResetCollectionChangedEventAtTheEndIfItemsAreClearedAndAdded()
{
var oc = new ObservableCollectionEx<string>
{
"Existing",
"Items"
};
var toAdd = new List<string>
{
"Foo",
"Bar"
};
var itemCount = 0;
var eventCount = 0;
var action = NotifyCollectionChangedAction.Add;
oc.CollectionChanged += (sender, args) =>
{
++eventCount;
itemCount = oc.Count;
action = args.Action;
};
oc.ClearAndAddRange(toAdd);
itemCount.Should().Be(2);
eventCount.Should().Be(1);
action.Should().Be(NotifyCollectionChangedAction.Reset);
}
示例5: ClearAndAddRangeClearsTheCollectionThenAddsAllTheItems
public void ClearAndAddRangeClearsTheCollectionThenAddsAllTheItems()
{
var oc = new ObservableCollectionEx<string>
{
"Existing",
"Items"
};
var toAdd = new List<string>
{
"Foo",
"Bar"
};
oc.ClearAndAddRange(toAdd);
oc.Should().ContainInOrder(toAdd);
oc.Should().OnlyContain(s => toAdd.Contains(s));
oc.Count.Should().Be(2);
}