private void OrderListBox_OnExecuteCommand(object sender, ExecutedRoutedEventArgs e) { var selected = this.OrderListBox.SelectedItems.Cast <MediaOrderItem>().ToArray(); bool activeSelected = selected.Any() && (selected.Count((item) => item == orderList.ActiveItem) != 0); MediaOrderItem boundaryItem; if (e.Command == CustomCommands.MoveUp) { boundaryItem = orderList.Move(selected, -1); if (boundaryItem != null) { OrderListBox.ScrollIntoView(boundaryItem); portfolioModified = true; } // set keyboard focus to last selected element (this is the element that // was selected last when using Shift+Arrow key selection, therefore this should keep // the selection where it was before) instead of moving focus to list box // where it would end up by default with Ctlr+Arrow keys. Keyboard.Focus((ListBoxItem)OrderListBox.ItemContainerGenerator.ContainerFromItem(selected.Last())); } else if (e.Command == CustomCommands.MoveDown) { boundaryItem = orderList.Move(selected, 1); if (boundaryItem != null) { OrderListBox.ScrollIntoView(boundaryItem); portfolioModified = true; } Keyboard.Focus((ListBoxItem)OrderListBox.ItemContainerGenerator.ContainerFromItem(selected.Last())); } else if (e.Command == ApplicationCommands.Delete) { if (selected.Any() && (!activeSelected || MessageBox.Show("Wollen Sie das aktive Element wirklich entfernen (Die Anzeige wird auf Blackscreen geschaltet, wenn die Präsentation gerade aktiv ist)?", "Aktives Element entfernen?", MessageBoxButton.YesNoCancel, MessageBoxImage.Warning) == MessageBoxResult.Yes)) { int index = this.OrderListBox.SelectedIndex; var selectedArray = selected.ToArray(); foreach (var item in selectedArray) { orderList.Remove(item); } if (index < this.OrderListBox.Items.Count) { this.OrderListBox.SelectedIndex = index; OrderListBox.ScrollIntoView(this.OrderListBox.SelectedItem); } else if (this.OrderListBox.HasItems) { this.OrderListBox.SelectedIndex = this.OrderListBox.Items.Count - 1; OrderListBox.ScrollIntoView(this.OrderListBox.SelectedItem); } portfolioModified = true; } } else if (e.Command == CustomCommands.Activate) { orderList.ActiveItem = selected.Last(); } else if (e.Command == NavigationCommands.Refresh) { // FIXME: If the focus is on another element than the OrderListBox, refresh does not work correctly ... foreach (var item in selected) { orderList.Reload(item); } } else if (e.Command == CustomCommands.OpenInEditor) { var ed = Controller.ShowEditorWindow(); foreach (var item in selected) { var song = item.Data as SongMedia; ed.LoadOrImport(song.Uri); } } }