public void CloseFile(OpenFileViewModel file) { int index = OpenFiles.IndexOf(file); Debug.Assert(index >= 0); file.Dispose(); OpenFiles.RemoveAt(index); if (--index < 0) { index = 0; } if (OpenFiles.Count > 0) { SelectedFile = OpenFiles[index]; } }