3

我正在使用 WPF 创建两个 ListView 并实现拖放功能。(intra-listview 和 inter-listview)

我在这里找到了一个有趣的帖子。

但是,有一个问题。当我从 listView1 中拖动一个 listviewitem 时,我只能在 listView1 中看到装饰器(幻影图像)。当我想将 listviewItem 放到 ListView2 上时,我也必须在那里看到装饰器。基本上,装饰器仅出现在开始拖动操作的 listView 上。一旦它在 listView 之外,它就会消失。

我做了一些研究,找不到一种方法让装饰器在启动拖动的控件之外可见。

谁能帮我一些建议?

4

1 回答 1

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();
    }
于 2011-06-22T05:34:00.547 回答