File Dropping does not work

SyntaxEditor for WPF Forum

Posted 9 years ago by PROCOS - PROCOS AG
Version: 14.2.0611
Platform: .NET 4.0
Environment: Windows 7 (64-bit)
Avatar

Hi

I try to enable file dropping on syntax editor WPF. I set AllowDrop=true and use the event PasteDropEvent:

private void editor_PasteDragDrop(object sender, PasteDragDropEventArgs e)
{
  if (e.Action == PasteDragDropAction.DragEnter)
    e.DragEventArgs.Effects = DragDropEffects.Copy;
  else if (e.Action == PasteDragDropAction.DragDrop && e.DataStore.GetDataPresent(DataFormats.FileDrop))
  {
    string[] files = e.DataStore.GetData(DataFormats.FileDrop) as string[];
    if (files != null && files.Length > 0)
    {
      using (FileStream stream = File.OpenRead(files[0]))
      {
        e.Text = new StreamReader(stream).ReadToEnd();
      }
    }
  }
}

It seems not to work in this way. I get the DragEnter event but no DragDrop. Similar code worked with the WinForms Syntax Editor. How can I implement this with WPF Syntax Editor?

Thanks in advance.

Martin

Comments (2)

Answer - Posted 9 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar

Hello,

Please check out the "SyntaxEditor / User Interface Features / Input/Output Features / Drag and Drop" topic for more information on how drag/drop works in the WPF version.  You should only need to handle that PasteDragDrop event but per the documentation topic, you need to ensure that e.Text is not null to allow the drop.  You can even just set e.Text to an empty string in e.Action == PasteDragDropAction.DragEnter and that should fix the problem.


Actipro Software Support

Posted 9 years ago by PROCOS - PROCOS AG
Avatar

Works. Thanks for your help!

The latest build of this product (v24.1.2) was released 2 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.