本文整理汇总了C#中ObservableList.AddRange方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableList.AddRange方法的具体用法?C# ObservableList.AddRange怎么用?C# ObservableList.AddRange使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ObservableList
的用法示例。
在下文中一共展示了ObservableList.AddRange方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddRange_FiresCollectionChanged
public void AddRange_FiresCollectionChanged()
{
var list = new ObservableList<int> { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
int eventFireCount = 0;
list.CollectionChanged += (sender, args) =>
{
eventFireCount++;
Assert.AreEqual(NotifyCollectionChangedAction.Add, args.Action);
switch (eventFireCount)
{
case 1:
Assert.AreEqual(9, args.NewStartingIndex);
Assert.IsTrue(new[] { 10 }.SequenceEqual(args.NewItems.Cast<int>()));
break;
case 2:
Assert.AreEqual(10, args.NewStartingIndex);
Assert.IsTrue(new[] { 11 }.SequenceEqual(args.NewItems.Cast<int>()));
break;
}
};
list.AddRange(new[] { 10, 11 });
}
示例2: AddRangeNotifiesAsResetInsteadOfIndividualItemsWhenItemCountAboveThresholdTest
public void AddRangeNotifiesAsResetInsteadOfIndividualItemsWhenItemCountAboveThresholdTest(int lowerLimit, int upperLimit)
{
// given
var rangeToAdd = Enumerable.Range(lowerLimit, upperLimit - lowerLimit + 1).ToList();
var testScheduler = new TestScheduler();
var testObserverCollectionChanges = testScheduler.CreateObserver<IObservableCollectionChange<int>>();
var testObserverResets = testScheduler.CreateObserver<Unit>();
using (var observableList = new ObservableList<int>())
{
// when
observableList.ThresholdAmountWhenChangesAreNotifiedAsReset = 0;
observableList.CollectionChanges.Subscribe(testObserverCollectionChanges);
observableList.Resets.Subscribe(testObserverResets);
testScheduler.Schedule(TimeSpan.FromTicks(100), () => { observableList.AddRange(rangeToAdd); });
testScheduler.Start();
// then
var shouldBeReset = rangeToAdd.Count >= observableList.ThresholdAmountWhenChangesAreNotifiedAsReset;
testObserverCollectionChanges.Messages.Count.Should().Be(shouldBeReset ? 1 : rangeToAdd.Count);
testObserverCollectionChanges.Messages.Should()
.Match(recordedMessages =>
recordedMessages.All(message => message.Value.Value.ChangeType == (shouldBeReset ? ObservableCollectionChangeType.Reset : ObservableCollectionChangeType.ItemAdded)));
testObserverResets.Messages.Count.Should().Be(shouldBeReset ? 1 : 0);
}
}
示例3: AddRange_ItemCountOverThresHold_FiresCollectionChanged
public void AddRange_ItemCountOverThresHold_FiresCollectionChanged()
{
var list = new ObservableList<int> { 1, 2, 3, 4, 5 };
list.CollectionChanged += (sender, args) => Assert.AreEqual(NotifyCollectionChangedAction.Reset, args.Action);
list.AddRange(new[] { 6, 7, 8, 9, 10 });
}
示例4: KeyImageClipboard
public KeyImageClipboard(StudyTree studyTree)
{
_studyTree = studyTree;
_currentContext = new KeyImageInformation();
_availableContexts = new ObservableList<KeyImageInformation> {_currentContext};
_availableContexts.AddRange(_studyTree.Studies
.SelectMany(s => s.Series)
.SelectMany(s => s.Sops)
.Where(s => s.SopClassUid == SopClass.KeyObjectSelectionDocumentStorageUid)
.Select(s => new KeyImageInformation(studyTree, s))
.OrderByDescending(s => s.ContentDateTime)
.ThenBy(s => s.SeriesNumber));
}
示例5: AddRangeIncreasesCountTest
public void AddRangeIncreasesCountTest(int lowerLimit, int upperLimit)
{
// given
var rangeToAdd = Enumerable.Range(lowerLimit, upperLimit - lowerLimit + 1).ToList();
var testScheduler = new TestScheduler();
var testObserver = testScheduler.CreateObserver<int>();
using (var observableList = new ObservableList<int>())
{
// when
observableList.ThresholdAmountWhenChangesAreNotifiedAsReset = rangeToAdd.Count + 1;
observableList.CountChanges.Subscribe(testObserver);
testScheduler.Schedule(TimeSpan.FromTicks(100), () => { observableList.AddRange(rangeToAdd); });
testScheduler.Start();
// then
observableList.Count.Should().Be(rangeToAdd.Count);
}
}
示例6: Convert
/// <summary>
/// The convert.
/// </summary>
/// <param name="value">
/// The value.
/// </param>
/// <param name="targetType">
/// The target type.
/// </param>
/// <param name="parameter">
/// The parameter.
/// </param>
/// <param name="culture">
/// The culture.
/// </param>
/// <returns>
/// </returns>
/// <exception cref="ArgumentNullException">
/// </exception>
/// <exception cref="NotImplementedException">
/// </exception>
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (targetType == null)
{
throw new ArgumentNullException("targetType");
}
var bytes = (byte[])value;
if (targetType.IsAssignableFrom(typeof(IEnumerable)))
{
var observable = new ObservableList<SixteenBytes>();
if (bytes != null && bytes.Length > 0)
{
Task.Factory.StartNew(
() =>
{
const int ChunkSize = 16;
var chunk = new List<SixteenBytes>(ChunkSize);
int n;
var len = bytes.Length;
for (n = 0; n < len; n += SixteenBytes.Size)
{
chunk.Add(new SixteenBytes { Value = bytes, Index = n });
if (chunk.Count == chunk.Capacity)
{
observable.AddRange(chunk);
chunk = new List<SixteenBytes>(ChunkSize);
}
}
if (n < len)
{
chunk.Add(new SixteenBytes { Value = bytes, Index = n });
}
if (chunk.Count > 0)
{
observable.AddRange(chunk);
}
});
}
return observable;
}
throw new NotImplementedException();
}
示例7: TestAddRange
public void TestAddRange()
{
var list = new List<string> { "aaa", "bbb", "ccc" };
var set = new ObservableList<string>(list);
Assert.AreEqual(set.Count, list.Count);
bool propertyChangedInvoked = false;
bool collectionChangedInvoked = false;
set.PropertyChanged += (sender, e) =>
{
Assert.AreEqual(e.PropertyName, nameof(ObservableList<string>.Count));
propertyChangedInvoked = true;
};
set.CollectionChanged += (sender, e) =>
{
Assert.AreEqual(e.Action, NotifyCollectionChangedAction.Add);
Assert.AreEqual(e.NewStartingIndex, 3);
Assert.NotNull(e.NewItems);
Assert.AreEqual(e.NewItems.Count, 2);
Assert.AreEqual(e.NewItems[0], "ddd");
Assert.AreEqual(e.NewItems[1], "eee");
collectionChangedInvoked = true;
};
set.AddRange(new[] { "ddd", "eee" });
Assert.AreEqual(set.Count, 5);
Assert.AreEqual(set[0], "aaa");
Assert.AreEqual(set[1], "bbb");
Assert.AreEqual(set[2], "ccc");
Assert.AreEqual(set[3], "ddd");
Assert.AreEqual(set[4], "eee");
Assert.True(propertyChangedInvoked);
Assert.True(collectionChangedInvoked);
}
示例8: AddRangeNotifiesCountAfterResetWhenItemCountAboveThresholdTest
public void AddRangeNotifiesCountAfterResetWhenItemCountAboveThresholdTest(int lowerLimit, int upperLimit)
{
// given
var rangeToAdd = Enumerable.Range(lowerLimit, upperLimit - lowerLimit + 1).ToList();
var testScheduler = new TestScheduler();
var testObserver = testScheduler.CreateObserver<int>();
using (var observableList = new ObservableList<int>())
{
// when
observableList.ThresholdAmountWhenChangesAreNotifiedAsReset = 0;
observableList.CountChanges.Subscribe(testObserver);
testScheduler.Schedule(TimeSpan.FromTicks(100), () => { observableList.AddRange(rangeToAdd); });
testScheduler.Start();
// then
testObserver.Messages.Count.Should().Be(1);
testObserver.Messages.Last().Should().NotBeNull();
testObserver.Messages.Last().Value.Value.Should().Be(observableList.Count);
}
}