Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>If you don't want to implement something complex than the Move Up and Move Down can be handled like this. If the source looks like this</p> <pre><code>public ObservableCollection&lt;FileClass&gt; FileNames { get; set; } private void moveUp_Click(object sender, RoutedEventArgs e) { FileClass selectedfile = listBox1.SelectedItem as FileClass; int index = FileNames.IndexOf(selectedfile); if (index &gt; 0) { FileNames.Remove(selectedfile); FileNames.Insert(index-1, selectedfile); listBox1.SelectedItem = selectedfile; } } private void moveDown_Click(object sender, RoutedEventArgs e) { FileClass selectedfile = listBox1.SelectedItem as FileClass; int index = FileNames.IndexOf(selectedfile); if (index &lt; FileNames.Count-1) { FileNames.Remove(selectedfile); FileNames.Insert(index + 1, selectedfile); listBox1.SelectedItem = selectedfile; } } </code></pre> <p><strong>CHANGE</strong><br> Try this code to move items up and down with drag and drop within the ListBox</p> <pre><code>private void listBox1_Drop(object sender, DragEventArgs e) { ListBox parent = sender as ListBox; FileClass data = e.Data.GetData(typeof(FileClass)) as FileClass; FileClass objectToPlaceBefore = GetObjectDataFromPoint(parent, e.GetPosition(parent)) as FileClass; if (data != null &amp;&amp; objectToPlaceBefore != null) { int index = FileNames.IndexOf(objectToPlaceBefore); FileNames.Remove(data); FileNames.Insert(index, data); listBox1.SelectedItem = data; } } private void listBox1_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e) { ListBox parent = sender as ListBox; FileClass data = GetObjectDataFromPoint(parent, e.GetPosition(parent)) as FileClass; if (data != null) { DragDrop.DoDragDrop(parent, data, DragDropEffects.Move); } } private static object GetObjectDataFromPoint(ListBox source, Point point) { UIElement element = source.InputHitTest(point) as UIElement; if (element != null) { object data = DependencyProperty.UnsetValue; while (data == DependencyProperty.UnsetValue) { data = source.ItemContainerGenerator.ItemFromContainer(element); if (data == DependencyProperty.UnsetValue) element = VisualTreeHelper.GetParent(element) as UIElement; if (element == source) return null; } if (data != DependencyProperty.UnsetValue) return data; } return null; } </code></pre> <p>That should complete the drag'n'drop.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload