private void deleteSelectedBaseMap(object sender, MessageBoxClosedArgs e) { if (e.Result != MessageBoxResult.OK) { return; } BaseMapInfo currentSelectedBaseMap = BaseMapsList.SelectedItem as BaseMapInfo; if (currentSelectedBaseMap == null) { return; } int currIndex = BaseMaps.IndexOf(currentSelectedBaseMap); BaseMaps.Remove(currentSelectedBaseMap); if (currIndex > BaseMaps.Count - 1) // if last item is being deleted { currIndex = BaseMaps.Count - 1; } if (currIndex > -1) // select the next item in the list { BaseMapsList.SelectedIndex = currIndex; } }
private void onMoveBaseMapDownCommand(object parameter) { BaseMapInfo currentSelectedBaseMap = BaseMapsList.SelectedItem as BaseMapInfo; if (currentSelectedBaseMap == null) { return; } int pos = BaseMaps.IndexOf(currentSelectedBaseMap); if (pos < 0 || pos >= BaseMaps.Count) { return; } BaseMaps.RemoveAt(pos); BaseMaps.Insert(pos + 1, currentSelectedBaseMap); // Preserve selection BaseMapsList.SelectedIndex = pos + 1; refreshMoveCommands(); }