public void SetSelection(TTrackedModel item) { if ((item == null && this.SelectedItem != null) || (item != null && this.SelectedItem == null) || (item != null && this.SelectedItem != null && !item.Id.Equals(this.SelectedItem.Id))) { var newStartingIndex = -1; if (item != null) { newStartingIndex = IndexOf(item.Id); if (newStartingIndex == -1) { // Cannot find selected item in tracked list. // Possible error condition. return; } } var oldStartingIndex = -1; if (this.SelectedItem != null) { oldStartingIndex = IndexOf(this.SelectedItem.Id); } var oldSelectedItem = this.SelectedItem; this.SelectedItem = item; NotifyTrackedListChanged(ChangedEventArgs.CreateSelectionChangedEventArgs(item, oldSelectedItem, newStartingIndex, oldStartingIndex)); } }