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


C# ObservableList.Add方法代码示例

本文整理汇总了C#中ObservableList.Add方法的典型用法代码示例。如果您正苦于以下问题:C# ObservableList.Add方法的具体用法?C# ObservableList.Add怎么用?C# ObservableList.Add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ObservableList的用法示例。


在下文中一共展示了ObservableList.Add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Click

		void Click()
		{
			if (click==0)
			{
				items = listView.DataSource;

				items.Add("Added from script 0");
				items.Add("Added from script 1");
				items.Add("Added from script 2");

				items.Remove("Caster");

				click += 1;
				return ;
			}
			if (click==1)
			{
				items.Clear();
				
				click += 1;
				return ;
			}
			if (click==2)
			{
				items.Add("test");
				
				click += 1;
				return ;
			}
		}
开发者ID:jaronimoe,项目名称:cellVIEW_animated,代码行数:30,代码来源:TestListView.cs

示例2: LocationsTreeViewModel

 public LocationsTreeViewModel(ObservableCollection<Location> locations)
 {
     Locations = new ObservableList<LocationNode>();
     foreach (var location in locations) Locations.Add(new LocationNode(location));
     locations.CollectionChanged += (s, e) =>
     {
         switch (e.Action)
         {
             case NotifyCollectionChangedAction.Add:
                 foreach (Location location in e.NewItems) Locations.Add(new LocationNode(location));
                 break;
             case NotifyCollectionChangedAction.Remove:
                 foreach (Location location in e.OldItems)
                 {
                     var item = Locations.FirstOrDefault(l => l.Location.Guid == location.Guid);
                     if (item != null) Locations.Remove(item);
                 }
                 break;
             case NotifyCollectionChangedAction.Replace:
                 foreach (Location location in e.OldItems)
                 {
                     var item = Locations.FirstOrDefault(l => l.Location.Guid == location.Guid);
                     if (item != null) Locations.Remove(item);
                 }
                 foreach (Location location in e.NewItems) Locations.Add(new LocationNode(location));
                 break;
             case NotifyCollectionChangedAction.Reset:
                 Locations.Clear();
                 foreach (Location location in e.NewItems) Locations.Add(new LocationNode(location));
                 break;
         }
     };
     LocationsTreeViewSource = new CollectionViewSource { Source = Locations };
     LocationsTreeViewSource.SortDescriptions.Add(new SortDescription("Location.Name", ListSortDirection.Ascending));
 }
开发者ID:AuditoryBiophysicsLab,项目名称:ESME-Workbench,代码行数:35,代码来源:LocationsTreeViewModel.cs

示例3: AddItemAfterSubscribing

 public void AddItemAfterSubscribing()
 {
     var source = new ObservableList<ObservableList<string>>();
     ImmutableList<string> result = ImmutableList<string>.Empty;
     source.ToLiveLinq()
         .SelectMany((list, _) => list.ToLiveLinq())
         .ToObservableEnumerable().Subscribe(value => result = value);
     source.Add(new ObservableList<string>());
     source.Add(new ObservableList<string>());
     result.Should().BeEmpty();
 }
开发者ID:ApocalypticOctopus,项目名称:Apocalyptic.Utilities.Net,代码行数:11,代码来源:SelectManyObservableCollectionTests.cs

示例4: DisposeSubscription_ThenRemoveItem

 public void DisposeSubscription_ThenRemoveItem()
 {
     var source = new ObservableList<ObservableList<string>>();
     ImmutableList<string> result = ImmutableList<string>.Empty;
     var subscription = source.ToLiveLinq()
         .SelectMany((list, _) => list.ToLiveLinq())
         .ToObservableEnumerable().Subscribe(value => result = value);
     source.Add(new ObservableList<string>());
     source.Add(new ObservableList<string>());
     source[0].Add("a");
     source[1].Add("c");
     subscription.Dispose();
     source.RemoveAt(1);
     result.Should().ContainInOrder("a", "c");
 }
开发者ID:ApocalypticOctopus,项目名称:Apocalyptic.Utilities.Net,代码行数:15,代码来源:SelectManyObservableCollectionTests.cs

示例5: CanAccumulate

        public void CanAccumulate()
        {
            var items = new ObservableList<Person>();


            var subscription = items.Changes
                .Subscribe(changes =>
                {
                    Console.WriteLine(changes);
                });


            using (var x = items.SuspendNotifications())
            {
                foreach (var person in _random.Take(20000))
                {
                    items.Add(person);
                }
                items.Clear();
                var result = items.GetChanges();

                items[10] = new Person("Roland", 1);
            }

        }
开发者ID:oysteinkrog,项目名称:DynamicData,代码行数:25,代码来源:TestCollection.cs

示例6: Data2Country

		ObservableList<TreeNode<ITreeViewSampleItem>> Data2Country(List<TreeViewSampleDataCountry> data)
		{
			var countries = new ObservableList<TreeNode<ITreeViewSampleItem>>();
			data.ForEach(x => countries.Add(Node(new TreeViewSampleItemCountry(x.Name, x.Flag))));

			return countries;
		}
开发者ID:jaronimoe,项目名称:cellVIEW_animated,代码行数:7,代码来源:TreeViewSampleData.cs

示例7: TestAdd

 public void TestAdd()
 {
     var list = new List<string> { "aaa", "bbb", "ccc" };
     var set = new ObservableList<string>(list);
     bool propertyChangedInvoked = false;
     bool collectionChangedInvoked = false;
     Assert.AreEqual(set.Count, list.Count);
     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, 1);
         Assert.AreEqual(e.NewItems[0], "ddd");
         collectionChangedInvoked = true;
     };
     set.Add("ddd");
     Assert.AreEqual(set[0], "aaa");
     Assert.AreEqual(set[1], "bbb");
     Assert.AreEqual(set[2], "ccc");
     Assert.AreEqual(set[3], "ddd");
     Assert.True(propertyChangedInvoked);
     Assert.True(collectionChangedInvoked);
 }
开发者ID:h78hy78yhoi8j,项目名称:xenko,代码行数:29,代码来源:TestObservableList.cs

示例8: Initialize

    public override void Initialize()
    {
        base.Initialize();

        Playables = new ObservableList<IPlayable>();
        foreach (var t in Resources.FindObjectsOfTypeAll<IPlayable>())
            Playables.Add(t);
    }
开发者ID:ylyking,项目名称:unity-1,代码行数:8,代码来源:PlayablesView.cs

示例9: TestAddRemoveDispose

 public void TestAddRemoveDispose()
 {
     var sourceList = new ObservableList<string>();
     var targetList = new Collection<string>();
     var syncer1 = new CollectionSyncer<string, string>(sourceList, targetList, (x) => x.ToUpper(), (x) => x.ToUpper(), false);
     var syncer2 = new CollectionSyncer<string, string>(sourceList, targetList, (x) => x.ToLower(), (x) => x.ToLower(), false);
     sourceList.Add("Test1");
     Assert.Equal(2, targetList.Count);
     Assert.True(targetList.Contains("test1"));
     Assert.True(targetList.Contains("TEST1"));
     sourceList.Remove("Test1");
     Assert.Equal(sourceList.Count, targetList.Count);
     Assert.Equal(0, targetList.Count);
     syncer2.Dispose();
     sourceList.Add("Test1");
     Assert.Equal(sourceList.Count, targetList.Count);
 }
开发者ID:ryanhorath,项目名称:Rybird.Framework,代码行数:17,代码来源:CollectionSyncerTests.cs

示例10: ObservableList_RaisesCollectionResetOnReverse

        public void ObservableList_RaisesCollectionResetOnReverse()
        {
            var list  = new ObservableList<Int32>();
            var reset = false;

            list.CollectionReset += (source) =>
            {
                reset = true;
            };
            list.Add(1);
            list.Add(2);
            list.Add(3);
            list.Add(4);
            list.Reverse();

            TheResultingValue(reset).ShouldBe(true);
        }
开发者ID:RUSshy,项目名称:ultraviolet,代码行数:17,代码来源:ObservableListTest.cs

示例11: AddItem

 public void AddItem()
 {
   _handle = new EventWaitHandle(false, EventResetMode.ManualReset);
   var test = new ObservableList<string>();
   test.ItemAdded += List_ItemEvent;
   test.Add("myValue");
   Assert.IsTrue(_handle.WaitOne(10));
 }
开发者ID:rnpowerconsulting,项目名称:appstract,代码行数:8,代码来源:ObservableListTests.cs

示例12: Delegates_AddingNewHandler_ShouldNotPassStringsWithoutFirstCapitalLetter

        public void Delegates_AddingNewHandler_ShouldNotPassStringsWithoutFirstCapitalLetter()
        {
            ObservableList<string> capitalLetters = new ObservableList<string>();
            capitalLetters.AddingNew += HandlerMethods.FirstLetterCapitalHandler;

            capitalLetters.Add("Brustwarzen");
            capitalLetters.Add("smellFungus");
            capitalLetters.Add("Mumpsimus");
            capitalLetters.Add("Jackanapes");
            capitalLetters.Add("hocus-Pocus");
            capitalLetters.Add("Fuddy-duddy");
            capitalLetters.Add("Batrachomyomachy");
            capitalLetters.Add("Fard");
            capitalLetters.Add("Handschuh");
            capitalLetters.Add("arschbombe");

            Assert.AreEqual(7, capitalLetters.Count);
        }
开发者ID:ondrejsevcik,项目名称:PieceOfCake,代码行数:18,代码来源:Tests.cs

示例13: Delegates_AddingNewHandler_ShouldNotPassOddNumbers

        public void Delegates_AddingNewHandler_ShouldNotPassOddNumbers()
        {
            ObservableList<int> evenNumbers = new ObservableList<int>();
            evenNumbers.AddingNew += HandlerMethods.EvenNumberHandler;

            evenNumbers.Add(0);
            evenNumbers.Add(1);
            evenNumbers.Add(2);
            evenNumbers.Add(3);
            evenNumbers.Add(4);
            evenNumbers.Add(5);
            evenNumbers.Add(6);
            evenNumbers.Add(7);
            evenNumbers.Add(8);
            evenNumbers.Add(9);

            Assert.AreEqual(5, evenNumbers.Count);
        }
开发者ID:ondrejsevcik,项目名称:PieceOfCake,代码行数:18,代码来源:Tests.cs

示例14: ChangeItem

 public void ChangeItem()
 {
   _handle = new EventWaitHandle(false, EventResetMode.ManualReset);
   var test = new ObservableList<string>();
   test.Add("myValue");
   test.ItemChanged += List_ItemEvent;
   test[test.IndexOf("myValue")] = "myNewValue";
   Assert.IsTrue(_handle.WaitOne(10));
 }
开发者ID:rnpowerconsulting,项目名称:appstract,代码行数:9,代码来源:ObservableListTests.cs

示例15: TestConstruction

        public void TestConstruction()
        {
            var badList = new List<string>();
            var sourceList = new ObservableList<string>();
            var targetList = new Collection<string>();
            Assert.Throws<ArgumentNullException>(() => new CollectionSyncer<string, string>(null, targetList, (x) => x, (x) => x, false));
            Assert.Throws<ArgumentNullException>(() => new CollectionSyncer<string, string>(sourceList, null, (x) => x, (x) => x, false));
            Assert.Throws<Exception>(() => new CollectionSyncer<string, string>(badList, targetList, (x) => x, (x) => x, false));

            sourceList.Add("Test1");
            sourceList.Add("Test2");
            var syncer1 = new CollectionSyncer<string, string>(sourceList, targetList, (x) => x, (x) => x, false);
            Assert.Equal(2, sourceList.Count);
            Assert.Equal(0, targetList.Count);

            var syncer2 = new CollectionSyncer<string, string>(sourceList, targetList, (x) => x, (x) => x, true);
            Assert.Equal(sourceList.Count, targetList.Count);
        }
开发者ID:ryanhorath,项目名称:Rybird.Framework,代码行数:18,代码来源:CollectionSyncerTests.cs


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