private void InsertIntervalRelativeTo(Interval toInsert, Interval relativeTo, string where) { if (relativeTo == null) { intervals.Add(toInsert); } else { var index = Intervals.IndexOf(relativeTo); if ("after".Equals(where)) { if (index != -1) { intervals.Insert(++index, toInsert); } else { intervals.Add(toInsert); } } if ("before".Equals(where)) { Intervals.Insert(index, toInsert); } } FirePropertyChanged("HasIntervals"); RefreshTemplate(); }