private void MoveItemDown(object obj) { if (selectedIndex == -1) { return; } lock (this) { Debug.Assert(selectedIndex >= 0, "SelectedIndex must be valid, not -1, for moving."); Debug.Assert( selectedIndex < (Highlighters.Count - 1), "SelectedIndex must be a value less than the max index of the collection."); Debug.Assert( Highlighters.Count > 1, "Can only move an item if there are more than one items in the collection."); var oldIndex = selectedIndex; SelectedIndex = -1; lock (Highlighters) { Highlighters.Swap(oldIndex, oldIndex + 1); } SelectedIndex = oldIndex + 1; } }
private void MoveItemUp(object obj) { if (selectedIndex != -1) { lock (this) { Debug.Assert(selectedIndex >= 0, "SelectedIndex must be valid, e.g not -1."); Debug.Assert( Highlighters.Count > 1, "Can not move item unless more than one item in the collection."); int oldIndex = selectedIndex; SelectedIndex = -1; lock (Highlighters) { Highlighters.Swap(oldIndex, oldIndex - 1); } SelectedIndex = oldIndex - 1; } } }