如何显示在WPF中拖动的项目?

The*_*boy 7 c# wpf drag-and-drop

我一直在研究WPF应用程序,它本质上是一个WYSIWYG编辑器,并且正在使用拖放功能.我有拖放功能,但需要使其更直观和用户友好.部分内容涉及实际显示被拖动的项目.最简单的方法是什么?我拖的项目并不特别,但我甚至不确定在哪里寻找如何做到这一点.

Aar*_*ver 8

你需要使用DragDrop.GiveFeedback等等; Jaime有一篇很棒的博客文章,概述了你所描述的不同场景.

来自Jaime博客文章处理光标操作的简单例子......

        private void StartDragCustomCursor(MouseEventArgs e)
        {

            GiveFeedbackEventHandler handler = new GiveFeedbackEventHandler(DragSource_GiveFeedback);
            this.DragSource.GiveFeedback += handler; 
            IsDragging = true;
            DataObject data = new DataObject(System.Windows.DataFormats.Text.ToString(), "abcd");
            DragDropEffects de = DragDrop.DoDragDrop(this.DragSource, data, DragDropEffects.Move);
            this.DragSource.GiveFeedback -= handler; 
            IsDragging = false;
        }

        void DragSource_GiveFeedback(object sender, GiveFeedbackEventArgs e)
        {
                try
                {
                    //This loads the cursor from a stream .. 
                    if (_allOpsCursor == null)
                    {
                        using (Stream cursorStream = System.Reflection.Assembly.GetExecutingAssembly().GetManifestResourceStream(
            "SimplestDragDrop.DDIcon.cur"))
                        {
                            _allOpsCursor = new Cursor(cursorStream);
                        } 
                    }
                    Mouse.SetCursor(_allOpsCursor);

                    e.UseDefaultCursors = false;
                    e.Handled = true;
                }
                finally { }
        }
Run Code Online (Sandbox Code Playgroud)