void CloseTab() { var oldSelItem = SelectedItem; bool resetSelItem = false; foreach (var vm in SelectedItems.ToArray()) { resetSelItem |= oldSelItem == vm; if (lastActivated == vm) { lastActivated = null; } documentTabService.Close(vm.Tab); Collection.Remove(vm); } if (resetSelItem) { SelectedItem = tabsList.Count == 0 ? null : tabsList[0]; } }