本文整理汇总了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);
}
}
}
示例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);
}
示例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;
}
}
}
}
示例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;
}
示例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();
}
示例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());
});
}
示例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);
}
示例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));
}
示例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);
};
}
示例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));
}
示例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;
}
示例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);
}
示例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());
}
示例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();
}
示例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);
}
});
}