question

njsokalski avatar image
0 Votes"
njsokalski asked FayWang-MSFT commented

Modifying DragEventArgs.Data or DragEventArgs.DataView during DragEnter

I have UWP app in which I want to allow the user to be able to drag an element, and when the element is dragged over another element (DragEnter), I want to change the target, and when they leave (DragExit), I want to change it back. To do this, I am storing the data about the item being dragged in args.Data.Properties during the DragStarting event. Then in the DragEnter event I use this data & attempt to temporarily store the data from the target element in e.DataView.Properties. However, this does not work because e.DataView.Properties is readonly. How can I modify the data in e.DataView.Properties during DragEnter & DragExit? Thanks.

windows-uwp
· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The Properties of e.DataView is read-only, you can not modify the data from it. Why do you want to change the data and change it back? Can you show more details about your expected behavior? Maybe we can find other solutions to achieve it.

0 Votes 0 ·

Hi, have you solved your issue? If not, can you provide more details about why you want to modify the data when dragging?

0 Votes 0 ·

1 Answer

jtorjo avatar image
0 Votes"
jtorjo answered FayWang-MSFT edited

Here's my suggestion: on DragStarting, add a custom object to e.Data.Properties.

Then, on DragEnter, get that object from e.DataView.Properties. Cast it to your object type. Then do whatever you want with it.

· 2
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

I actually thought about doing it that way, although I was hoping to avoid creating an extra class/type. I'm sure I'm not the only person that has ever had this scenario, so I just figured there would be a more built-in way to do it. Is there any other way, or is that my only choice? Thanks.


0 Votes 0 ·

During dragging, there is no method can directly change the data, maybe you could use the above suggestion to achieve it.

0 Votes 0 ·