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


C# ObservableList类代码示例

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


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

示例1: 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

示例2: object

        private object _busysem = new object(); // semaphore

        #endregion Fields

        #region Constructors

        public SerialConnTest()
        {
            ADCValues = new ObservableList<VoltPoint>();
            Connection = (Application.Current as App).CurrentSerialConnection;
            RCUCom = new RCUCommunication(Connection);
            RCUCom.ProgressChanged += RaiseProgressChanged;
        }
开发者ID:apmKrauser,项目名称:RCUModulTest,代码行数:13,代码来源:SerialConnTest(ViewModel).cs

示例3: 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

示例4: 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

示例5: OnReportingCompleted

 private void OnReportingCompleted(ObservableList<PendingReport>.ListChangedEventArgs e, ResultCompletionEventArgs args)
 {
     if (e.Item.ReportCompletedCallback != null)
     {
         e.Item.ReportCompletedCallback(e.Item.Exception, args.WasCancelled);
     }
 }
开发者ID:pirvudoru,项目名称:winbugfreak,代码行数:7,代码来源:ErrorHandler.cs

示例6: SoftphoneEngine

        public SoftphoneEngine()
        {
            _sync = new object();

            // set license here

            PhoneLines = new ObservableList<IPhoneLine>();
            PhoneCalls = new ObservableList<IPhoneCall>();
            LogEntries = new ObservableList<LogEntry>();
            InstantMessages = new ObservableList<string>();
            CallHistory = new CallHistory();
            CallTypes = new List<CallType> { CallType.Audio, CallType.AudioVideo };

            // enable file logging
            InitLogger();

            // create softphone
            MinPort = 20000;
            MaxPort = 20500;
            //LocalIP = SoftPhoneFactory.GetLocalIP();
            InitSoftphone(false);

            // create media
            MediaHandlers = new MediaHandlers();
            MediaHandlers.Init();
        }
开发者ID:linkinheroes,项目名称:OzekiDemoSoftphoneWPF,代码行数:26,代码来源:SoftphoneEngine.cs

示例7: 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

示例8: CanHaveManyComputeds

        public void CanHaveManyComputeds()
        {
            var prefix = new Observable<string>("Before");

            var contacts = new ObservableList<Contact>(
                Enumerable.Range(0, 10000)
                    .Select(i => new Contact()
                    {
                        FirstName = "FirstName" + i,
                        LastName = "LastName" + i
                    }));

            var projections = new ComputedList<Projection>(() =>
                from c in contacts
                select new Projection(prefix, c));
            string dummy;
            foreach (var projection in projections)
                dummy = projection.Name;
            Assert.AreEqual("BeforeFirstName3LastName3", projections.ElementAt(3).Name);

            prefix.Value = "After";
            foreach (var projection in projections)
                dummy = projection.Name;
            Assert.AreEqual("AfterFirstName3LastName3", projections.ElementAt(3).Name);
        }
开发者ID:Railgun-it,项目名称:Assisticant,代码行数:25,代码来源:LargeListTest.cs

示例9: TagLineListForm

		public TagLineListForm(IServiceProvider provider, IEnumerable<TagLineInfo> tagLines)
		{
			if (provider == null)
				throw new ArgumentNullException(nameof(provider));
			if (tagLines == null)
				throw new ArgumentNullException(nameof(tagLines));

			_serviceManager = new ServiceContainer(provider);

			_tagLines = new ObservableList<TagLineInfo>(tagLines);

			InitializeComponent();

			_serviceManager.Publish<ITagLineListFormService>(new TagLineListFormService(this));
			_serviceManager.Publish<IDefaultCommandService>(new DefaultCommandService("Janus.Forum.TagLine.Edit"));

			_toolbarGenerator = new StripMenuGenerator(_serviceManager, _toolStrip, "Forum.TagLine.Toolbar");
			_contextMenuGenerator = new StripMenuGenerator(_serviceManager, _contextMenuStrip, "Forum.TagLine.ContextMenu");

			_listImages.Images.Add(
				_serviceManager.GetRequiredService<IStyleImageManager>()
					.GetImage(@"MessageTree\Msg", StyleImageType.ConstSize));

			UpdateData();

			_tagLines.Changed += (sender, e) => UpdateData();
		}
开发者ID:rsdn,项目名称:janus,代码行数:27,代码来源:TagLineListForm.cs

示例10: FilteredPhotoModel

        public FilteredPhotoModel(Windows.Storage.StorageFile file, ObservableList<Filter> filters)
        {
            _photo = new PhotoModel(file);

            Filters = filters;
            Filters.ItemsChanged += Filters_ItemsChanged;
        }
开发者ID:roachhd,项目名称:filter-explorer,代码行数:7,代码来源:FilteredPhotoModel.cs

示例11: Project

 public Project()
 {
     // Default projects
     details = new ProjectDetails ();
     buttons = new ObservableList <ButtonProjectElement> ();
     elements = new List <ProjectElement> ();
 }
开发者ID:GNOME,项目名称:mistelix,代码行数:7,代码来源:Project.cs

示例12: 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

示例13: 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

示例14: AddHousesListListeners

		private void AddHousesListListeners(ObservableList<House> child)
		{
			if (child == null)
				return;
				
			var notifyPropertyChanging = child as INotifyPropertyChanging;
// ReSharper disable ConditionIsAlwaysTrueOrFalse
			if (notifyPropertyChanging != null)
// ReSharper restore ConditionIsAlwaysTrueOrFalse
				notifyPropertyChanging.PropertyChanging += HousesListPropertyChangingEventHandler;
				
			var notifyPropertyChanged = child as INotifyPropertyChanged;
// ReSharper disable ConditionIsAlwaysTrueOrFalse
			if (notifyPropertyChanged != null)
// ReSharper restore ConditionIsAlwaysTrueOrFalse
				notifyPropertyChanged.PropertyChanged += HousesListPropertyChangedEventHandler;
				
			var notifyChildPropertyChanged = child as INotifyCollectionChanged;
// ReSharper disable ConditionIsAlwaysTrueOrFalse
			if (notifyChildPropertyChanged != null)
// ReSharper restore ConditionIsAlwaysTrueOrFalse
				notifyChildPropertyChanged.CollectionChanged += HousesListChangedEventHandler;
				
			foreach (var item in child)
				AddHousesItemListeners(item);
		}
开发者ID:pescuma,项目名称:modelsharp,代码行数:26,代码来源:BasePerson.generated.cs

示例15: ListCollectionView

		public ListCollectionView (IList collection)
			: base (collection)
		{
			var interfaces = SourceCollection.GetType ().GetInterfaces ();
			foreach (var t in interfaces) {
				if (t.IsGenericType && t.GetGenericTypeDefinition () == typeof (IList<>)) {
					Type type = t.GetGenericArguments () [0];
					ItemConstructor = type.GetConstructor (Type.EmptyTypes);
				}
			}

			UpdateCanAddNewAndRemove ();
			filteredList = new ObservableList<object> ();
			RootGroup = new RootCollectionViewGroup (null, null, 0, false, SortDescriptions);
			CurrentPosition = -1;
			IsEmpty = ActiveList.Count == 0;
			MoveCurrentToPosition (0);

			if (SourceCollection is INotifyCollectionChanged)
				((INotifyCollectionChanged) SourceCollection).CollectionChanged += HandleSourceCollectionChanged;

			GroupDescriptions.CollectionChanged += (o, e) => Refresh ();
			((INotifyCollectionChanged) SortDescriptions).CollectionChanged += (o, e) => {
				if (IsAddingNew || IsEditingItem)
					throw new InvalidOperationException ("Cannot modify SortDescriptions while adding or editing an item");
				Refresh ();
			};

			filteredList.CollectionChanged += HandleFilteredListCollectionChanged;
			RootGroup.CollectionChanged += HandleRootGroupCollectionChanged;
		}
开发者ID:kangaroo,项目名称:moon,代码行数:31,代码来源:StandardCollectionView.cs


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