async void IDropTarget.Drop(IDropInfo dropInfo) { var source = (Component.TrackButton)VisualTreeHelper.GetChild(dropInfo.DragInfo.VisualSourceItem, 0); int sourceIdx = ItemsControlHelper.FindIndexByItemChild(panelTracks, source); int targetIdx = dropInfo.InsertIndex - 1; // nothing need to work if (sourceIdx == targetIdx) { return; } if (sourceIdx > targetIdx) { targetIdx--; } var sourceItem = dropInfo.Data as PlexTrack; var targetItem = targetIdx == -1 ? null : ((Component.TrackButton)ItemsControlHelper.GetItemChildByIndex(panelTracks, targetIdx)).Track; // move it panelTracks.IsEnabled = false; var app = (App)Application.Current; try { await app.plexClient.MoveTrackInPlaylist(Playlist, sourceItem, targetItem); // update UI Tracks.Remove(sourceItem); Tracks.Insert(targetIdx == -1 ? 0 : targetIdx, sourceItem); } catch { MessageBox.Show("Failed to update data in the remote server.", "PlexFlux", MessageBoxButton.OK, MessageBoxImage.Exclamation); } finally { panelTracks.IsEnabled = true; } }