Handling DragEnter event in WPF

Amyco 35 40 Reputation points
2023-08-16T22:27:32.2766667+00:00

Hello,

I'm developing a WPF desktop application, in C# under VS 2022 17.7.1 Community,

I need to deal with dragging and dropping an Excel document onto a Grid.

The processing of the Drag_Enter event consists in checking the data of the Excel document and validating or not the operation by specifying a value to the argument e.Effect. OK.

This check is long because I launch Excel (hidden) to access the document data. And during this time the cursor does not validate the operation and the user is entitled to think that it is not allowed.

At the beginning of the processing of the Drag_Enter event, I therefore want to display waiting information in the direction of the user by changing a visual element of the GUI. I did this by changing the background color of an element but this operation is only effective when the Drag_Enter processing exits, so too late.

Is there a way to operate that allows a WPF element to be displayed before the Drag_Enter event has finished processing?

Many thanks for your help.

Windows 10
Windows 10
A Microsoft operating system that runs on personal computers and tablets.
12,075 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Limitless Technology 44,691 Reputation points
    2023-08-17T13:09:43.92+00:00

    Hello there,

    In Windows Presentation Foundation (WPF), the DragEnter event is a routed event that is raised when an object is dragged into the bounds of an element. The event handlers associated with this event can perform various operations, such as validating the dragged data and updating the UI. However, the UI updates might not be immediately visible if they are performed synchronously within the event handler, potentially leading to a delay in rendering the UI changes.

    If you want to ensure that a WPF element is displayed before the DragEnter event finishes processing, you can utilize asynchronous programming techniques to achieve smoother UI updates.

    Hope this resolves your Query !!

    --If the reply is helpful, please Upvote and Accept it as an answer--

    0 comments No comments

  2. Amyco 35 40 Reputation points
    2023-08-17T15:20:10.7533333+00:00

    Hi,

    Thank you for your answer which confirms what I think. It's the data validation that needs to be asynchronous.

    But can you provide me with a brief example of asynchronous operation that implements the GDI display during data validation work? I don't think I've ever done that...

    Thank you very much for your help.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.