Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 747063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T14:09:44+00:00 2026-05-14T14:09:44+00:00

I have a drag/drop operation on a Canvas that is supposed to do something

  • 0

I have a drag/drop operation on a Canvas that is supposed to do something when an object gets dragged into and out of it. My problem is that the DragEnter/DragLeave events keeps firing as the mouse moves the object over it, not just on enter/exit. The faster the mouse is moving, the more frequently the events fire.

The Canvas DragOver Event moves the Canvas.Top/Left of the DraggedObject and I think that might be my problem, but I am not sure how I would fix this.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T14:09:45+00:00Added an answer on May 14, 2026 at 2:09 pm

    Here is the sequence of events:

    1. Your mouse moves from where you clicked it across the Panel. No events fire.
    2. Your mouse reaches the edge of the Panel and enters the Canvas. The DragEnter event fires on the Canvas.
    3. Your DragEnter handler moves the Panel so that it is now under the mouse. Since the mouse is no longer over the Canvas (it is over the Panel), the DragLeave event fires.
    4. Your mouse moves further, reaching the edge of the Panel again. Steps 2 and 3 repeat.

    The faster you move the mouse, the more events you will receive.

    The essence of your problem is that drag-drop uses hit testing, and by moving your panel you are defeating the ability of hit testing to see “behind” your panel to know what container it is being dropped in.

    The solution is to use your own code for drag and drop handling, which is really not difficult at all. WPF’s hit testing engine is powerful enough to do hit-testing behind the current object but drag-drop doesn’t make use of this functionality. You can use it directly however by using the VisualTreeHelper.HitTest overload that takes a HitTestFilterCallback and a HitTestResultCallback. Just pass it a filter that ignores any hits within the panel being dragged.

    I’ve found that for scenarios like you describe, doing drag-drop by handling mouse events is actually easier than using the built in DoDragDrop because you don’t have to deal with the complexity (DataObject, DragDropEffects, QueryContinueDrag, etc). This additional complexity is very important for enabling scenarios of dragging between applications and processes, but does not help you for what you are doing.

    Here’s the simple solution:

    1. On MouseDown with left button down, record the position (on MouseLeave erase the position)
    2. On MouseMove with {left button down, position recorded, current mouse position differs by more than delta} set a flag saying drag operation is in progress & capture the mouse
    3. On MouseMove with drag operation in progress, use hit testing to determine where your panel should be (ignoring the panel itself) and adjust its parenting and position accordingly.
    4. On MouseUp with drag operation in progress, release the mouse capture and clear the “drag operation is in progress” flag

    Enjoy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know that when a drag/drop operation is completed, upon receiving a MouseUp or
i have done drag and drop using with jquery. here i have issue that
I am performing a drag-and-drop operation of an anchor text selected in a browser
I've got a UL of items using jQuery UI that I have drag and
I have a drag-and-drop event handler registered to a parent form, this.DragDrop += new
I have a WPF 4 application where I have implemented Drag and Drop using
I have done drag and drop work using with jquery plug-in, Jquery: $(document).ready(function() {
i have created the drag and drop work. Here i can place the drag
Is it possible to have a WPF window/element detect the drag'n'dropping of a file
I have a datagrid which is populated with CSV data when the user drag/drops

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.