连接 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();
}