private void MoveToTop(ObservableCollection <LogCurveItem> channels, LogCurveItem indexChannel) { // If the channel is not found in the channel list get out var index = channels.IndexOf(indexChannel); if (index < 0) { return; } // Remove the channel from its current position in the list and insert it at the top channels.RemoveAt(index); channels.Insert(0, indexChannel); }
private int MoveChannel(LogCurveItem logCurveItem, ObservableCollection <LogCurveItem> sourceChannels, ObservableCollection <LogCurveItem> destinationChannels, int selectedIndex = -1) { // If the selected channel cannot be found in the source list get out var channelSelectedIndex = -1; // Channel was found in the source list and is removed. if (sourceChannels.Contains(logCurveItem)) { channelSelectedIndex = selectedIndex == -1 ? sourceChannels.IndexOf(logCurveItem) : selectedIndex; sourceChannels.Remove(logCurveItem); } // Channel is added to the destination list and notifications are sent about changes to both lists destinationChannels.Add(logCurveItem); NotifyOfPropertyChange(() => HasSelected); NotifyOfPropertyChange(() => HasAvailable); // Return the index of the channel removed if the list has that many items, otherwise return the index above the channel return(channelSelectedIndex <= (sourceChannels.Count - 1) ? channelSelectedIndex : channelSelectedIndex - 1); }