WPF C#: Rearrange items in listbox via drag and drop

前端 未结 7 1084
你的背包
你的背包 2020-11-27 12:08

I am trying to figure out how to move the items in a pre-populated listbox up and down via mouse drags.

I have looked at the Control.DoDragDrop method from microsof

7条回答
  •  独厮守ぢ
    2020-11-27 12:59

    This has helped me greatly thank you. Especially the generics version.

    I made the following amendments:

    Because I don't set the DataContext of the ListBox (just the ItemsSource), I use

    var items = this.ItemsSource as IList;
    

    in the Move method.

    And at the end of "Move" I added:

    this.SelectedItem = source;
    

    as I want the user to have the moved item as the current selection.

提交回复
热议问题