Here's an easy one for one of you smart folks -- I have an observable collection containing viewmodel objects. I'm trying to go through the objects and remove any where the plant.Living property is "No". I am using this code:
foreach (PlantViewModel plant in Plants)
{
if (plant.Living == "No")
{
Plants.Remove(plant);
}
}
PlantsViewSource.Source = Plants;
PlantsGridView.SelectedItem = null;
However, when the first object is encountered that meets the criteria and that object is removed, it modifies the collection and the foreach throws an error. How can I remove the objects from the collection in another way?