我正在使用WPF创建两个ListView并实现拖放功能。 (列表内查看和列表间查看)
我找到了一篇有趣的帖子here。
然而,有一个问题。当我从listView1拖动listviewitem时,我只在listView1中看到了adorner(ghost图像)。当我想在ListView2上删除listviewItem时,我必须在那里看到它的装饰。基本上,装饰器仅出现在拖动操作开始的listView上。一旦它在listView之外,它就会消失。
我做了一些研究,无法找到一种方法,让装饰体可以在控件的外部显示。
有人可以帮我提一些建议吗?
答案 0 :(得分:2)
将GiveFeedback事件连接起来,以更新列表视图之外的装配工位置。从下面的示例和方法更新了ListView属性(并且在listview_DragLeave方法中,您不希望折叠装饰器):
/// <summary>
/// Gets/sets the ListView whose dragging is managed. This property
/// can be set to null, to prevent drag management from occuring. If
/// the ListView's AllowDrop property is false, it will be set to true.
/// </summary>
public ListView ListView
{
get { return listView; }
set
{
if( this.IsDragInProgress )
throw new InvalidOperationException( "Cannot set the ListView property during a drag operation." );
if( this.listView != null )
{
#region Unhook Events
this.listView.PreviewMouseLeftButtonDown -= listView_PreviewMouseLeftButtonDown;
this.listView.PreviewMouseMove -= listView_PreviewMouseMove;
this.listView.DragOver -= listView_DragOver;
this.listView.DragLeave -= listView_DragLeave;
this.listView.DragEnter -= listView_DragEnter;
this.listView.GiveFeedback -= listView_GiveFeedback;
this.listView.Drop -= listView_Drop;
#endregion // Unhook Events
}
this.listView = value;
if( this.listView != null )
{
if( !this.listView.AllowDrop )
this.listView.AllowDrop = true;
#region Hook Events
this.listView.PreviewMouseLeftButtonDown += listView_PreviewMouseLeftButtonDown;
this.listView.PreviewMouseMove += listView_PreviewMouseMove;
this.listView.DragOver += listView_DragOver;
this.listView.DragLeave += listView_DragLeave;
this.listView.DragEnter += listView_DragEnter;
this.listView.GiveFeedback += listView_GiveFeedback;
this.listView.Drop += listView_Drop;
#endregion // Hook Events
}
}
}
void listView_GiveFeedback(object sender, GiveFeedbackEventArgs e)
{
if (this.ShowDragAdornerResolved)
this.UpdateDragAdornerLocation();
}