如何显示在WPF中拖动的项目? [英] How do I show the item that is being dragged in WPF?

查看:104
本文介绍了如何显示在WPF中拖动的项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在使用一个基本上是所见即所得编辑器的WPF应用程序,并且正在使用拖放功能。我有拖放功能工作,但需要使其更直观和用户友好。其中的一部分将涉及实际显示被拖动的项目。最简单的方法是什么?我拖拉的东西没什么特别的,但我甚至不知道在哪里寻找如何做到这一点。

I have been working on a WPF Application that is essentially a WYSIWYG editor, and is using drag and drop functionality. I have the drag and drop functionality working, but need to make it more intuitive and user friendly. Part of this will involve actually showing the item being dragged. What is the easiest way to do this? The items I am dragging are nothing really special,but I am not even sure where to look for how to do this.

推荐答案

您将需要使用 DragDrop.GiveFeedback 等等; Jaime有一个很好的博客帖子,概述了您描述的不同场景。

You will need to make use of DragDrop.GiveFeedback amongst other things; Jaime has a great blog post outlining varying scenarios of which the one you describe is included.

从Jaime的博客文章中处理光标操作的简单示例。 ..

Trivial example from Jaime's blog post in dealing with cursor manipulation...

        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 { }
        }

这篇关于如何显示在WPF中拖动的项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆