当前位置: 首页>>代码示例>>C#>>正文


C# ObservableList.AddRange方法代码示例

本文整理汇总了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 });
        }
开发者ID:mdabbagh88,项目名称:Rareform,代码行数:27,代码来源:ObservableListTest.cs

示例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);
            }
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:29,代码来源:ObservableListAddMultipleItemsTests.cs

示例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 });
        }
开发者ID:mdabbagh88,项目名称:Rareform,代码行数:8,代码来源:ObservableListTest.cs

示例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));
		}
开发者ID:m-berkani,项目名称:ClearCanvas,代码行数:14,代码来源:KeyImageClipboard2.cs

示例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);
            }
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:20,代码来源:ObservableListAddMultipleItemsTests.cs

示例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();
        }
开发者ID:andysoftdev,项目名称:ht4n,代码行数:68,代码来源:ValueConverters.cs

示例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);
 }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:32,代码来源:TestObservableList.cs

示例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);
            }
        }
开发者ID:jbattermann,项目名称:JB.Common,代码行数:22,代码来源:ObservableListAddMultipleItemsTests.cs


注:本文中的ObservableList.AddRange方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。