当前注册人数423000人 邮箱: 密码: 注册新用户 忘记密码
首页 C/C++/MFC C# ASP.NET VB.NET MATLAB Android   站内搜索 下载代码说明/积分规则
为什么要注册?

1. 可以直接免费从本站下载代码,防止邮件发送不到您的邮箱,或登录不了国外网站

2. 可以设定关键字,当有您关心的代码收录时,邮件通知您

3. 对这里的代码进行评分和评论

4. 可以和大家一起分享你的源代码,得到更多的建议

Drag and Drop Items in a WPF ListView

拖拽WPF中ListView表项的源代码

2007年12月09日
C# 2.0, Windows, .NET 3.0, XAML, WPF, VS2005, Dev
本程序实现了一个非常智能的ListViewDragDropManager类,它实现WPF中ListView的item的自动拖拽,使用这个类,你可以在同一个listview中拖放item,也可以从一个listview中拖放到另外一个listview里。这个类会自动绘制出用户正在拖动和即将放置的位置。
相关知识

基本的使用方法:

As promised earlier, the ListViewDragDropManager allows you to have full-featured drag-and-drop in a ListView with just one line of code. Here's that one line:

new ListViewDragDropManager<Foo>( this.listView );

There are a few things to point out about that one line of code. You might want to put it in a Window's Loaded event handling method, so that the ListView has drag-and-drop support as soon as the Window opens. The 'Foo' type parameter indicates what type of objects the ListView is displaying. The ListView's ItemsSource property must reference an ObservableCollection<Foo>. Alternatively the ItemsSource property could be bound to the DataContext property, and have the latter reference an ObservableCollection<Foo>.

Before going any further into how to use the ListViewDragDropManager, let's take a look at its public properties:

  • DragAdornerOpacity - Gets/sets the opacity of the drag adorner. This property has no effect if ShowDragAdorner is false. The default value is 0.7
  • IsDragInProgress - Returns true if there is currently a drag operation being managed.
  • ListView - Gets/sets the ListView whose dragging is managed. This property can be set to null, to prevent drag management from occurring. If the ListView's AllowDrop property is false, it will be set to true.
  • ShowDragAdorner - Gets/sets whether a visual representation of the ListViewItem being dragged follows the mouse cursor during a drag operation. The default value is true.

There is also one event exposed:

  • ProcessDrop - Raised when a drop occurs. By default the dropped item will be moved to the target index. Handle this event if relocating the dropped item requires custom behavior. Note, if this event is handled the default item dropping logic will not occur.

源代码原文下载:
Drag and Drop Items in a WPF ListView This article presents a class called ListViewDragDropManager, which automates drag-and-drop operations in the WPF ListView. It allows the user to drag and drop items within a ListView, or drag items from one ListView to another. The class is smart enough to figure out where in the ListView the user wants to drop an item, and will insert the item at that location automatically. The class also exposes several properties and one event that enables a developer to customize the way that the drag-and-drop operations behave.

源码图片

点击链接查看大图
从本站下载附件及源代码(1个附件,已经成功下载1047次)

最值得关注的外文源代码

Clog - Client Logging, WPF Edition
ListView with Image on SubItems
Drag and drop gridview item for ordering in ASP.Net 2.0
Folder tree with drag and drop
评论(评论是增加积分的一个有效途径)
字数在300字内
请如实评论
本源代码共评论111次,此处显示最近20次评论! 查看所有评论

会飞的小兔  2015年08月18日
谢谢了 以后一定顶
会飞的小兔  2015年08月18日
学习了 多传几个
yunnan  2015年06月06日
实用
ha1234  2014年08月14日
下载学习 学习
xitangzi  2014年04月22日
挺好,学习学习
flagship_yhj  2014年04月01日
正在学习用WPF实现拖拽的功能,很有用,谢谢!
xy2dfh  2013年07月26日
很实用,谢谢分享 学习了!
xy2dfh  2013年07月26日
很实用,谢谢分享 学习了!
xy2dfh  2013年07月26日
很实用,谢谢分享 学习了!
linda  2012年09月07日
这个可以有,下了学习,thx
656561836  2012年08月30日
谢谢分享
zj3351  2012年08月15日
学习下~
gu_xiaoliang  2012年07月11日
下载学习 学习
Jack  2012年04月09日
很不错啊
gongzaijin  2012年03月06日
very good!
kjnb  2012年01月30日
值得大家学习
woyaoxiazai  2012年01月14日
我觉得挺好的
三塔那  2011年12月01日
不错的东西,值得大家学习
chenjijie  2011年11月30日
我很喜欢这个例子
java18  2011年11月06日
不错
字数在300字内
请如实评论
200万国内源码搜索
CopyRight (C) codesoso.com 2007-2009 All Rights Reserved zhihuishi   免责声明