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


C# ObservableCollection.Remove方法代码示例

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


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

示例1: HandleCollectionChanges

        private void HandleCollectionChanges(Client client, NotifyCollectionChangedEventArgs args, ObservableCollection<Interlocutor> actualCollection, ObservableCollection<object> nullCollection)
        {
            if (actualCollection.Count == 0)
            {
                nullCollection.Clear();
                nullCollection.Add(new NullInterlocutor(client));
                return;
            }
            var nullInterlocutor = nullCollection.OfType<NullInterlocutor>().FirstOrDefault();
            if (nullInterlocutor != null)
            {
                nullCollection.Remove(nullInterlocutor);
            }

            if (args.OldItems != null)
            {
                foreach (var oldItem in args.OldItems)
                {
                    nullCollection.Remove(oldItem);
                }
            }

            if (args.NewItems != null)
            {
                foreach (var newItem in args.NewItems)
                {
                    nullCollection.Insert(actualCollection.IndexOf((Interlocutor) newItem), newItem);
                }
            }
        }
开发者ID:zhongleiyang,项目名称:vstalk,代码行数:30,代码来源:InterlocutorCollectionConverter.cs

示例2: setNewParent

        public static void setNewParent(Guid itemId, Guid parentId, ObservableCollection<Todo> _Todos)
        {
            var thisItm = _Todos.FirstOrDefault(x=>x.Id==itemId);

            if (parentId!= Guid.Empty)
            {
                var prnt = _Todos.FirstOrDefault(x => x.Id == parentId);
                thisItm.ParentId = prnt.Id;
                thisItm.Wbs = prnt.Wbs + ">";
                int newIdx = _Todos.IndexOf(prnt)+1;
                if (newIdx <= _Todos.Count)
                {
                    _Todos.Remove(thisItm);
                    _Todos.Insert(newIdx, thisItm);
                }
                else
                {
                    _Todos.Remove(thisItm);
                    _Todos.Add(thisItm);
                }
            }
            else
            {
                thisItm.ParentId = Guid.Empty;
                thisItm.Wbs = ">";
            }

            //_Todos[itemIndex] = thisItm;
            updateChildren(thisItm, _Todos);
        }
开发者ID:amitthk,项目名称:wpftdm,代码行数:30,代码来源:MainWindowUIHelper.cs

示例3: RemoveAttachment

        private void RemoveAttachment(ObservableCollection<IProtectAttachment> attachments, string recordKey, string id)
        {
            foreach (IProtectAttachment protectAttachment in attachments)
            {
                if (IsCancellationPending)
                    return;

                if (string.IsNullOrEmpty(protectAttachment.RecordKey) ||
                    string.IsNullOrEmpty(recordKey))
                {
                    // The record keys are not available revert to using the id
                    if (protectAttachment.Id == id)
                    {
                        protectAttachment.Status = PropertyNames.UserRemovedAttachment;
                        attachments.Remove(protectAttachment);
                        protectAttachment.Dispose();
                        return;
                    }
                }
                else
                {
                    if (protectAttachment.RecordKey == recordKey)
                    {
                        protectAttachment.Status = PropertyNames.UserRemovedAttachment;
                        attachments.Remove(protectAttachment);
                        protectAttachment.Dispose();
                        return;
                    }
                }
            }
        }
开发者ID:killbug2004,项目名称:WSProf,代码行数:31,代码来源:RemoveAttachmentsAction.cs

示例4: Collision

        public ObservableCollection<GameObject> Collision(List<GameObject> attackers, List<GameObject> defenders,
            ObservableCollection<GameObject> gameObjects, int canvasHeight, out int numberOfCollisions)
        {
            var collisions = 0;

            foreach (var attacker in attackers)
            {
                var attackerRectangle = new Rect(attacker.Left, attacker.Top,
                    attacker.ImageWidth, attacker.ImageHeight);

                foreach (var defender in defenders)
                {
                    var defenderRectangle = new Rect(defender.Left, defender.Top,
                        defender.ImageWidth, defender.ImageHeight);

                    var collisionDetected = attackerRectangle.IntersectsWith(defenderRectangle);
                    if (collisionDetected)
                    {
                        gameObjects.Remove(attacker);
                        if (defender.Type != GameObjectType.Player)
                        {
                            gameObjects.Remove(defender);
                        }


                        collisions += 1;
                        break;
                    }
                }
            }


            numberOfCollisions = collisions;
            return gameObjects;
        }
开发者ID:enirtac,项目名称:DiceInvaders,代码行数:35,代码来源:CollisionHandler.cs

示例5: ContactsVM

 public ContactsVM()
 {
     _DB = new ContactsContext();
     soapClient = new SoapService.SoapServiceClient();
     Contacts = new ObservableCollection<Contact>();
     Addresses = new ObservableCollection<Address>();
     Companies = new ObservableCollection<Company>();
     AddressIDs = new ObservableCollection<int>();
     /* Old save command
     SaveCommand = new DelegateCommand(() => {
         _DB.SaveChanges();
     });
      */
     SaveCommand = new DelegateCommand(() => {
         foreach (var x in Contacts) {
             soapClient.AddContact(x);
         }
         soapClient.Save();
     });
     /*old Add Contact
     AddContactCommand = new DelegateCommand(() => {
         ViewingContact = new Contact();
         Contacts.Add(ViewingContact);
         _DB.Contacts.Add(VewingContact);
     });
      */
     AddContactCommand = new DelegateCommand(() => {
         ViewingContact = new Contact();
         Contacts.Add(ViewingContact);
         //soapClient.AddContactAsync(ViewingContact);
     });
     AddCompanyCommand = new DelegateCommand(() => {
         ViewingCompany = new Company();
         Companies.Add(ViewingCompany);
         _DB.Companies.Add(ViewingCompany);
     });
     AddAddressCommand = new DelegateCommand(() => {
         ViewingAddress = new Address();
         Addresses.Add(ViewingAddress);
         _DB.Addresses.Add(ViewingAddress);
     });
     DeleteContactCommand = new DelegateCommand(() => {
         _DB.Contacts.Remove(ViewingContact);
         Contacts.Remove(ViewingContact);
     });
     DeleteCompanyCommand = new DelegateCommand(() => {
         _DB.Contacts.Remove(ViewingContact);
         Contacts.Remove(ViewingContact);
     });
     DeleteAddressCommand = new DelegateCommand(() => {
         _DB.Contacts.Remove(ViewingContact);
         Contacts.Remove(ViewingContact);
     });
     AddContactMethodCommand = new DelegateCommand(() => {
         var cm = new ContactMethod();
         ViewingContact.ContactMethods.Add(cm);
     });
     init();
 }
开发者ID:karashak1,项目名称:fallCSharp,代码行数:59,代码来源:ContactsVM.cs

示例6: TasksViewModel

        public TasksViewModel(ITaskHub taskHub)
        {
            Tasks = new ObservableCollection<Task>();
              TaskStatuses = new ObservableCollection<string>{ "Open", "Closed", "On Hold" };

              Messenger.Default.Register<GotTasksForUserEvent>(this, (e) => {
            Tasks.Clear();
            foreach (Task task in e.Tasks) {
              Tasks.Add(task);
            }
              });

              Messenger.Default.Register<AddedTaskEvent>(this, (e) => {
            Tasks.Add(e.AddedTask);
              });

              Messenger.Default.Register<UpdatedTaskEvent>(this, (e) => {
            if (e == null || e.UpdatedTask == null) {
              return;
            }
            Task taskToUpdate = Tasks.FirstOrDefault(t => t.TaskID == e.UpdatedTask.TaskID);
            if (taskToUpdate != null) {
              if (taskToUpdate.IsDeleted || taskToUpdate.AssignedTo != Username) {
            Tasks.Remove(taskToUpdate);
              } else {
            taskToUpdate.AssignedTo = e.UpdatedTask.AssignedTo;
            taskToUpdate.Details = e.UpdatedTask.Details;
            taskToUpdate.Status = e.UpdatedTask.Status;
            taskToUpdate.Title = e.UpdatedTask.Title;
            taskToUpdate.IsDeleted = e.UpdatedTask.IsDeleted;
              }
            } else {
              // This is a new assigned task
              Tasks.Add(e.UpdatedTask);
            }
              });

              Messenger.Default.Register<DeletedTaskEvent>(this, (e) => {
            if (e == null || e.DeletedTask == null) {
              return;
            }
            Task deletedTask = Tasks.FirstOrDefault(t => t.TaskID == e.DeletedTask.TaskID);
            if (deletedTask != null) {
              Tasks.Remove(deletedTask);
            }
              });

              Messenger.Default.Register<LoginEvent>(this, (e) => {
            Username = e.Username;
              });

              AddTask = new RelayCommand(() => {
            Messenger.Default.Send(new NewTaskEvent());
              });
        }
开发者ID:sunilmunikar,项目名称:TaskR,代码行数:55,代码来源:TasksViewModel.cs

示例7: Items_Removed_From_Source_After_Mirror_Call_Are_Removed_From_Target

        public void Items_Removed_From_Source_After_Mirror_Call_Are_Removed_From_Target() {
            var target = new List<int>();
            var source = new ObservableCollection<int> { 1, 2, 3, 4, 5 };

            target.Mirror(source);
            source.Remove(1);
            source.Remove(3);
            source.Remove(5);

            target.Should().Equal(source);
        }
开发者ID:HFFernandes,项目名称:ReactiveUI.Contrib,代码行数:11,代码来源:CollectionSynchronizationMixinTest.cs

示例8: DynamicListVM

        public DynamicListVM(Action<string, string> popup)
        {
            _popup = popup;

            Items = new ObservableCollection<DynamicListItem>
            {
                new DynamicListItem() {Id = 1, Name = "Initial"},
                new DynamicListItem() {Id = 2, Name = "Added"}
            };
            SimpleItems = new ObservableCollection<string> { "Initial", "Added" };

            AddItemCommand = new Command(() =>
            {
                var max = 0;
                if (Items.Count > 0)
                    max = Items.Max(i => i.Id);
                Items.Add(new DynamicListItem { Id = ++max, Name = EntryText });
                SimpleItems.Add(EntryText);
            });
            UpdateItemCommand = new Command(() =>
            {
                Items[0].Name = "Update: " + Items[0].Name;
                SimpleItems[0] = "Update: " + SimpleItems[0];
            });
            SelectedItemCommand = new Command<DynamicListItem>((item) => _popup("Item Selected", string.Format("You selected {0}", item.Name)));
            DeleteItemCommand = new Command<DynamicListItem>((item) => Items.Remove(item));
        }
开发者ID:JC-Chris,项目名称:XFExtensions,代码行数:27,代码来源:DynamicListVM.cs

示例9: TestCollections

		public void TestCollections ()
		{
			var addCount = 0;
			var removeCount = 0;
			var addSum = 0;
			var removeSum = 0;

			var foo = new ObservableCollection<int> ();

			foo.CollectionChanged += (object sender, NotifyCollectionChangedEventArgs e) => {

				if (e.Action == NotifyCollectionChangedAction.Add) {
					addCount += 1;
					addSum += e.NewItems.Cast<int> ().Sum (x => x);
				}

				if (e.Action == NotifyCollectionChangedAction.Remove) {
					removeCount += 1;
					removeSum += e.OldItems.Cast<int> ().Except (e.NewItems.Cast<int> ()).Sum (x => x);
				}

				foo.Add (1);
				Assert.AreEqual (addCount, 1);
				Assert.AreEqual (addSum, 1);

				foo.Add (2);
				Assert.AreEqual (addCount, 2);
				Assert.AreEqual (addSum, 3);

				foo.Remove (2);
				Assert.AreEqual (addCount, 1);
				Assert.AreEqual (addSum, 2);
			};
		}
开发者ID:caloggins,项目名称:DOT-NET-on-Linux,代码行数:34,代码来源:ObservableCollectionExampleTests.cs

示例10: IterationViewModel

        public IterationViewModel(int level, ObservableCollection<FuzzyVariableViewModel> inputScope,
            ObservableCollection<FuzzyVariableViewModel> allVariables)
        {
            _level = level;
            InputScope = inputScope;
            OutputScope = new ObservableCollection<FuzzyVariableViewModel>(inputScope);

            inputScope.CollectionChanged += (sender, args) =>
            {
                if (args.NewItems != null)
                {
                    foreach (var item in args.NewItems)
                    {
                        OutputScope.Add(item as FuzzyVariableViewModel);
                    }
                }

                if (args.OldItems != null)
                {
                    foreach (var item in args.OldItems)
                    {
                        OutputScope.Remove(item as FuzzyVariableViewModel);
                    }
                }
            };
            Rules = new ObservableCollection<RuleViewModel>();
            Rules.CollectionChanged += onRulesCollectionChanged;

            AddRule = new DelegateCommand(p => Rules.Add(new RuleViewModel(inputScope, allVariables)));

            RemoveRule = new DelegateCommand(p => Rules.Remove(p as RuleViewModel));
        }
开发者ID:splmatthias,项目名称:FuzzyLab,代码行数:32,代码来源:IterationViewModel.cs

示例11: SceneViewerControl

        public SceneViewerControl()
        {
            Tabs = new ObservableCollection<SceneTabViewModel>();

            RemoveTab = new RelayCommand((obj) =>
            {
                Tabs.Remove(obj as SceneTabViewModel);
                //MessageBox.Show("New Folder!");
            });

            InitializeComponent();
            AssignPanelEventHandling(xna);

            ScenesControl.ItemsSource = Tabs;

            if (DesignerProperties.GetIsInDesignMode(this))
                return;

            _game = new MyGame(xna.Handle);
            _game.GameWorld.UpdateWorld = false;
            _context = _game.GraphicsContext;

            var gameWorldArg =
                new ConstructorArgument(
                    ApplicationProperties.ISceneViewerGameWorldArgName,
                    _game.GameWorld);
            _controller = DependencyInjectorHelper
                            .MainWindowKernel
                            .Get<ISceneViewerController>(gameWorldArg);
            _controller.Control = this;
        }
开发者ID:TiagoJSM,项目名称:Storytime,代码行数:31,代码来源:SceneViewerControl.xaml.cs

示例12: PmfUserDetailsViewModel

		public PmfUserDetailsViewModel(PmfUsersViewModel parentViewModel, GKUser user = null)
		{
			_parentViewModel = parentViewModel;
			UserTypes = new ObservableCollection<GKCardType>(Enum.GetValues(typeof(GKCardType)).OfType<GKCardType>());
			UserTypes.Remove(GKCardType.Employee);

			if (user == null)
			{
				_isNew = true;
				Title = "Создание пользователя";
				var password = parentViewModel.Users.Count > 0 ? parentViewModel.Users.Max(x => x.User.Password) + 1 : 1;
				user = new GKUser 
				{
					Password = password, 
					ExpirationDate = DateTime.Now.AddYears(1), 
					Fio = "Новый пользователь", 
					UserType = GKCardType.Operator 
				};
			}
			else
			{
				_oldUser = user;
				Title = "Редактирование пользователя " + user.Fio;
			}
			CopyProperties(user);
		}
开发者ID:xbadcode,项目名称:Rubezh,代码行数:26,代码来源:PmfUserDetailsViewModel.cs

示例13: SelectTest

        public void SelectTest()
        {
            var c = new ObservableCollection<string>()
            {
                "Item1",
                "Item2",
                "Item3",
                "Item4",
                "Item5",
            };

            var q = c.AsObservableQuery()
                .Select(i => new { Value = i })
                .AsObservableQuery()
                .ToObservableView();
            q.CollectionChanged += q_CollectionChanged;

            Assert.AreEqual(q.Count(), 5);

            c.Add("TestItem1");
            Assert.AreEqual(1, added);
            Assert.AreEqual(6, q.Count());

            c.Remove("TestItem1");
            Assert.AreEqual(1, removed);
            Assert.AreEqual(5, q.Count());
        }
开发者ID:Kinnara,项目名称:OLinq,代码行数:27,代码来源:SelectTests.cs

示例14: FenetreGestionAdmin

        public FenetreGestionAdmin()
        {
            //Delegate pour exécuter du code personnalisé lors du changement de langue de l'UI.
            CultureManager.UICultureChanged += CultureManager_UICultureChanged;

            InitializeComponent();

            // Header de la fenetre
            App.Current.MainWindow.Title = Nutritia.UI.Ressources.Localisation.FenetreGestionAdmin.Titre;

            //Récupère tout les membres de la BD.
            listMembres = new ObservableCollection<Membre>(serviceMembre.RetrieveAll());

            //Récupère le temps de DerniereMaj (Mise à jour) des membres le plus récent et l'enregistre dans
            //currentTime et previousTime.
            currentTime = previousTime = listMembres.Max(m => m.DerniereMaj);

            //On enlève le membre actuellement connecté de la liste pour qu'il ne puisse pas intéragir sur son propre compte.
            listMembres.Remove(listMembres.FirstOrDefault(x => x.NomUtilisateur == App.MembreCourant.NomUtilisateur));

            //Configure la dataGrid de la searchBox et le predicate pour le filtre.
            filterDataGrid.DataGridCollection = CollectionViewSource.GetDefaultView(listMembres);
            filterDataGrid.DataGridCollection.Filter = new Predicate<object>(Filter);

            //De listMembres, obtient la liste des administrateurs seulement.
            listAdmins = new ObservableCollection<Membre>(listMembres.Where(m => m.EstAdministrateur).ToList());

            dgAdmin.ItemsSource = listAdmins;
            adminDepart = listAdmins.ToList();

            //Configuration du thread. Met en background pour forcer la terminaison lorsque le logiciel se ferme.
            dbPoolingThread = new Thread(PoolDB);
            dbPoolingThread.IsBackground = true;
            dbPoolingThread.Start();
        }
开发者ID:Nutritia,项目名称:nutritia,代码行数:35,代码来源:FenetreGestionAdmin.xaml.cs

示例15: PopupViewModel

        public PopupViewModel()
        {
            Locations = new ObservableCollection<PopupLocationItem>();
            LocationSelectedCommand = new Command<PopupLocationItem>((item) =>
            {
                if (!Locations.Contains(item)) return;

                foreach (PopupLocationItem items in Locations)
                {
                    items.IsSelected = false;
                }

                item.IsSelected = true;

                if (LocationSelected != null)
                {
                    LocationSelected(this, item);
                }
                             
            });

            LocationRemovedCommand = new Command<PopupLocationItem>((item) =>
            {
                Locations.Remove(item);

                if (LocationRemoved != null)
                {
                    LocationRemoved(this, item);
                }
            });
       
        }
开发者ID:iejeecee,项目名称:mediaviewer,代码行数:32,代码来源:PopupViewModel.cs


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