DragEnter and Drop event won't be fired on a ToolWindow

Docking/MDI for WPF Forum

Posted 10 years ago by Andreas Boerzel - Software Architect, REALTECH Software Products GmbH
Version: 9.1.0507
Platform: .NET 4.0
Environment: Windows 7 (32-bit)
Avatar
Hello,
I want to create multiple AnalyzerDocuments (DocumentWindow) on the DockSite "dockSite" of my AnalyzerView (UserControl). The content of each AnalyzerDocument (DocumentWindow) also contains a DockSite "_workspace" that contains multiple CustomLayoutPanels (ToolWindow). I need to drag objects into the CustomLayoutPanels (ToolWindow) but the DragEnter and Drop events on my CustomLayoutPanel won't be fired.

Sample:


<UserControl x:Class="Realtech.ControlCenter.Client.Modules.Analyzer.AnalyzerView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"      
            xmlns:shared="http://schemas.actiprosoftware.com/winfx/xaml/shared"
     xmlns:docking="http://schemas.actiprosoftware.com/winfx/xaml/docking"              
             mc:Ignorable="d" 
             HorizontalAlignment="Stretch" VerticalAlignment="Stretch"
             d:DesignHeight="600" d:DesignWidth="850"
             MinHeight="200" MinWidth="200" >
   <docking:DockSite x:Name="dockSite" >
         <!-- Workspace -->
         <docking:Workspace Background="Transparent">
            <docking:TabbedMdiHost x:Name="tabbedMdiHost" >
               <docking:TabbedMdiContainer Name="tabbedMdiContainer" />
            </docking:TabbedMdiHost>
         </docking:Workspace>
   </docking:DockSite>
</UserControl>



   public partial class AnalyzerView : UserControl
   {  
      public AnalyzerView()
      {
         InitializeComponent();

         AnalyzerDocument document1 = new AnalyzerDocument(dockSite);
         AnalyzerDocument document2 = new AnalyzerDocument(dockSite);
         AnalyzerDocument document3 = new AnalyzerDocument(dockSite);
         AnalyzerDocument document4 = new AnalyzerDocument(dockSite);

         tabbedMdiContainer.Items.Add(document1);
         tabbedMdiContainer.Items.Add(document2);
         tabbedMdiContainer.Items.Add(document3);
         tabbedMdiContainer.Items.Add(document4);
      }
   }

   public class AnalyzerDocument : DocumentWindow
   {
      DockSite _workspace = null;

      public AnalyzerDocument(DockSite dockSite)
         : base(dockSite)
      {
         _workspace = new DockSite();
         Content = _workspace;

         AllowDrop = true;

         AddCustomLayoutPanel();
         AddCustomLayoutPanel();
         AddCustomLayoutPanel();
      }

      private void AddCustomLayoutPanel()
      {
         CustomLayoutPanel panel = new CustomLayoutPanel(_workspace);
      }
   }

   public class CustomLayoutPanel : ToolWindow
   {
      Canvas _workspace = null;
      Point _dropPosition = new Point();

      public CustomLayoutPanel(DockSite dockSite)
         : base(dockSite)
      {
         _workspace = new Canvas();
         Content = _workspace;

         AllowDrop = true;

         Dock();

         this.DragEnter += new DragEventHandler(OnDragOver);
         this.Drop += new DragEventHandler(OnDrop);
      }

      private void OnDragOver(object sender, DragEventArgs e)
      {
         if (e.Data.GetDataPresent(typeof(string)))
         {
            e.Effects = DragDropEffects.Copy;
         }
         else
         {
            e.Effects = DragDropEffects.None;
         }
      }

      private void OnDrop(object sender, DragEventArgs e)
      {
         _dropPosition = e.GetPosition(_workspace);

     ... do somthing...
      }
   }

I think it's a bug!?
Is there a workaround??

Thanks Andreas

Comments (2)

Posted 10 years ago by Actipro Software Support - Cleveland, OH, USA
Avatar
Hi Andreas,

As mentioned in my reply to your other post, the tool window is only represented in the UI by a tab. Therefore you want to attach your events to the root content element of the tool window instead.

If you do this, it works:
_workspace.AllowDrop = true;
_workspace.Background = Brushes.Transparent;  // Ensure a non-null background is set
_workspace.DragEnter += new DragEventHandler(OnDragOver);
_workspace.Drop += new DragEventHandler(OnDrop);


Actipro Software Support

Posted 10 years ago by Andreas Boerzel - Software Architect, REALTECH Software Products GmbH
Avatar
Yes, that works!
Thank you very much for your answer!

Andreas
The latest build of this product (v2019.1 build 0684) was released 17 days ago, which was after the last post in this thread.

Add Comment

Please log in to a validated account to post comments.