private void OrderListBox_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { Point p = e.GetPosition(OrderListBox); oldIndex = OrderListBox.GetIndexAtPosition(p); if (oldIndex >= 0) { startPoint = p; } }
private void OrderListBox_DragEnterOrOver(object sender, DragEventArgs e) { int index = OrderListBox.GetIndexAtPosition(e.GetPosition(OrderListBox)); this.RemoveInsertionAdorner(); if (index >= 0) { var container = OrderListBox.ItemContainerGenerator.ContainerFromIndex(index) as FrameworkElement; this.CreateInsertionAdorner(container, e.GetPosition(container).IsInFirstHalf(container, true)); } else if (OrderListBox.HasItems) { var container = OrderListBox.ItemContainerGenerator.ContainerFromIndex(OrderListBox.Items.Count - 1) as FrameworkElement; this.CreateInsertionAdorner(container, false); } //e.Effects = DragDropEffects.Move; }
private void PopulateOrderListBox() { OrderListBox.Items.Clear(); foreach (var item in orderRep.Items) { OrderListBox.Items.Add($"{item.Name} | {item.Price:$0.00}"); } OrderListBox.Refresh(); var subTotal = orderRep.Items.Sum(item => item.Price); var itbis = subTotal * 0.18; var tip = subTotal * 0.10; var total = subTotal + itbis + tip; SubTotalBox.Text = $"{subTotal:$0.00}"; ITBISBox.Text = $"{itbis:$0.00}"; TipBox.Text = $"{tip:$0.00}"; TotalBox.Text = $"{total:$0.00}"; }
void OrderListBox_Drop(object sender, DragEventArgs e) { try { this.RemoveInsertionAdorner(); int index = OrderListBox.GetIndexAtPosition(e.GetPosition(OrderListBox)); FrameworkElement container; bool isInFirstHalf = false; if (index >= 0) { container = OrderListBox.ItemContainerGenerator.ContainerFromIndex(index) as FrameworkElement; isInFirstHalf = e.GetPosition(container).IsInFirstHalf(container, true); } else { index = OrderListBox.HasItems ? OrderListBox.Items.Count - 1 : 0; } // Data comes from list itself if (e.Data.GetData(typeof(MediaOrderItem)) != null) { if (oldIndex < 0 || index == oldIndex) { return; } if (index < oldIndex) { index++; } if (isInFirstHalf) { index--; } MediaOrderItem movedItem = orderList[oldIndex]; if (index < 0) { orderList.Move(new MediaOrderItem[] { movedItem }, orderList.Count - oldIndex - 1); } else { orderList.Move(new MediaOrderItem[] { movedItem }, index - oldIndex); } oldIndex = -1; } // Data comes from song list else if (e.Data.GetData(SongDataObject.SongDataFormat) != null) { if (OrderListBox.HasItems) { index++; } if (isInFirstHalf) { index--; } SongData data = (SongData)e.Data.GetData(SongDataObject.SongDataFormat); Media m = MediaManager.LoadMediaMetadata(data.Uri, null); orderList.Insert(index, m); } // Data comes from explorer else if (e.Data.GetData(DataFormats.FileDrop) != null) { if (OrderListBox.HasItems) { index++; } if (isInFirstHalf) { index--; } string[] files = (string[])e.Data.GetData(DataFormats.FileDrop); IEnumerable <Media> result; if (files.Length < 1) { return; } if (files.Length == 1) { if (MediaManager.TryLoadPortfolio(files[0], out result)) { // TODO: maybe insert contents at drop position if the portfolio isn't empty? Controller.OpenPortfolio(files[0]); } else { Media m = MediaManager.LoadMediaMetadata(new Uri(files[0]), null); orderList.Insert(index, m); } } else { foreach (var m in MediaManager.LoadMultipleMediaMetadata(files.Select(f => new Uri(f)))) { orderList.Insert(index++, m); } } } else if (e.Data.GetData(typeof(String)) != null) { string data = (string)e.Data.GetData(typeof(String)); Uri u = null; if (!Uri.TryCreate(data, UriKind.Absolute, out u)) { Uri.TryCreate("http://" + data, UriKind.Absolute, out u); } if (u != null) { Media m = MediaManager.LoadMediaMetadata(u, null); orderList.Insert(index, m); } } } catch (Exception ex) { Controller.ShowUnhandledException(ex, false); } }
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); } } }