2011-02-02 27 views
7

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

回答

8

您将需要使用DragDrop.GiveFeedback以及其他东西; Jaime有一个很棒的blog post概述了你所描述的不同场景。

在处理光标操纵海梅的博客文章简单的例子...

 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 { } 
     } 
相关问题