I am looping through an ObservableCollection for items that have been marked by setting a boolean to true. After doing what I need with the item I want to remove it from the OnservableCollection. I can't do that within the foreach loop, so I was thinking of making a list of all the items marked, then after the foreach loop just clear all the items from the collection at once. But I can't even get started because I don't know how to get the index of the item in the foreach loop.
private void Upload()
{
List<TestResult> kill;
foreach (var tr in TestResults)
{
if (tr.CanUpload)
{
StatusContent = "Uploading " + tr.FileName;
FileOps.UploadDocument(tr);
kill.Add(tr);
tr.CanUpload = false;
RaisePropertyChanged("TestResults");
}
}
//this doesn't work
//TestResults.Remove(TestResults.Where(x => x.CanUpload == true));
}
I've tried working with what I have above, but I am missing some critical pieces to make it work right.