简体   繁体   English

WPF MVVM C#:拖放没有代码的列表框

[英]WPF MVVM C#: listbox drag and drop without code behind

I'm trying to figure out how to reorder the listbox without any code behind. 我试图弄清楚如何重新排序列表框而没有任何代码。 I tried following this post: WPF C#: Rearrange items in listbox via drag and drop It definitely works, but I want to do it with ICommand or AttachBehavior. 我尝试了以下帖子: WPF C#:通过拖放重新排列列表框中的项目确实可行,但是我想使用ICommand或AttachBehavior做到这一点。

Any suggestion? 有什么建议吗? How to hook the Drop and PreviewMouseLeftButtonDownEvent with AttachBehavior? 如何使用AttachBehavior挂钩Drop和PreviewMouseLeftButtonDownEvent?

The Listbox's ItemsSource is a Observable Collection. 列表框的ItemsSource是一个Observable集合。

Check out this CodeProject article. 查看 CodeProject文章。 This implementation rely on two attached properties DragEnabled and DropEnabled . 此实现依赖于两个附加属性DragEnabledDropEnabled

<ListBox lib:DragAndDrop.DragEnabled="true"/> // Source
<ListBox lib:DragAndDrop.DropEnabled="true"/> // Target

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM