Thank you so much, I was gonna ask about the implementation in ListView, but you said that at the end of the video. I will be waiting for that and more.
Correct Boukri, that will be coming soon! 😄 I think the source code has the ListView implementation if you're interested in seeing it. I'll admit it's a bit complex.
I know this video isn't new anymore, but it really helped me a lot! Can you tell me, how to avoid that first jumping, when movng the mouse? I assume this happens, because we don't click on the most top left edge of the square and so it snaps to the position of the mouse. I guess you'd somehow have to calculate the mouse offset?
Actually I found a solution. In case anybody else is wondering about this: In the MouseDown EventHandler you can save an offsetLeft and offsetTop by getting e.GetPosition(frameworkElement).X and e.FetPosition(frameworkElement).Y respectively
@@PanCave Thanks for the idea! I was wondering the same. If anyone wonders how to do this in more detail, you can declare a Point member currentMouseOffset and then in the rectangle's MouseDown event store e.GetPosition(rectangle) in there. Then, in the canvas's DragOver and Drop events you subtract that offset's x- and y-values from the mouse position to set the rectangles new position on the canvas. One must use the MouseDown event instead of the MouseMove event to obtain correct values for the offset.
Thanks TIRAN! I think the source code has the ListView implementation if you're interested in checking it out, but I think the video will clarify a lot of the concepts.
Hello Could you please also explain how to implement drag to the dynamically created elements? I tried to do that, but as soon as I try to move a rectangle it disappears, even though that I use single canvas
I can help with that. In the MouseMove event handler you'll want to use the object "sender" instead of the name reference. You'll need to cast it to a different object type. A UIElement would work. In my case I used a Shape object so I could change the fill color. Here's a simple example of what you want: --- private void Element_MouseMove(object sender, MouseEventArgs e) { if (e.LeftButton == MouseButtonState.Pressed) { DragDrop.DoDragDrop((UIElement)sender, new DataObject(DataFormats.Serializable, sender), DragDropEffects.Move); } } --- I know you posted this 8 months ago, but I hope it helps someone.
@@SingletonSean I've tried to implement drag and drop from my app window to photoshop window. (As if I drag image from windows explorer) and it didn't work. I've not spent much time on this, but I think it has something to do with what "datatype" other window expects.
Hy. Can you show a Drag&Drop-Excample for a List? Based on your example, I would like to create these lists variably and then be able to move them among each other. In addition, it should still be possible to move the contents of the list among each other. could you show an example, please.
I was trying to create a custom reporting tool that customers can drog and drop labels, images or draw lines and rectangles, and save the report for later use. But could not find where to start. Do you have a suggestion for me ? liked & subbed
Thank you Sir for your Tutorial... it's really awesome and so helpful... :) :) can you you make some tutorial about how to customize a GridView and make it with awesome look and functions.?
I imagine it would be something like that! I feel like this wouldn't be that crazy to create, but would certainly be somewhat difficult. I've actually done 2 drag and drop projects in the past that are related to this. The drag and drop is the easy part, but the hard part is enforcing a "grid" structure that the draggable pieces will snap to. Since I have some experience with this and some old source code, I'd love to do a video on the "grid" behavior. It's super satisfying too, hahah. Thanks for bringing up this topic!
Thank you so much, I was gonna ask about the implementation in ListView, but you said that at the end of the video. I will be waiting for that and more.
Correct Boukri, that will be coming soon! 😄 I think the source code has the ListView implementation if you're interested in seeing it. I'll admit it's a bit complex.
@@SingletonSean I will check it after all :D
Thanks for this! Wonderful timing too, I was just about to tackle this in my project! Appreciate your videos!
Woohoo, thanks Joe!
I know this video isn't new anymore, but it really helped me a lot! Can you tell me, how to avoid that first jumping, when movng the mouse? I assume this happens, because we don't click on the most top left edge of the square and so it snaps to the position of the mouse. I guess you'd somehow have to calculate the mouse offset?
Actually I found a solution. In case anybody else is wondering about this: In the MouseDown EventHandler you can save an offsetLeft and offsetTop by getting e.GetPosition(frameworkElement).X and e.FetPosition(frameworkElement).Y respectively
@@PanCave Thanks for the idea! I was wondering the same. If anyone wonders how to do this in more detail, you can declare a Point member currentMouseOffset and then in the rectangle's MouseDown event store e.GetPosition(rectangle) in there. Then, in the canvas's DragOver and Drop events you subtract that offset's x- and y-values from the mouse position to set the rectangles new position on the canvas. One must use the MouseDown event instead of the MouseMove event to obtain correct values for the offset.
Great stuff thanks a lot! Ill be eagerly awaiting a video covering listview 😉
Thanks TIRAN! I think the source code has the ListView implementation if you're interested in checking it out, but I think the video will clarify a lot of the concepts.
Hello
Could you please also explain how to implement drag to the dynamically created elements? I tried to do that, but as soon as I try to move a rectangle it disappears, even though that I use single canvas
I can help with that. In the MouseMove event handler you'll want to use the object "sender" instead of the name reference. You'll need to cast it to a different object type. A UIElement would work. In my case I used a Shape object so I could change the fill color. Here's a simple example of what you want:
---
private void Element_MouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed)
{
DragDrop.DoDragDrop((UIElement)sender, new DataObject(DataFormats.Serializable, sender), DragDropEffects.Move);
}
}
---
I know you posted this 8 months ago, but I hope it helps someone.
Do you plan to show the ways to implement this using MVVM?
Definitely Cyril! That will be next 💪
Thank you so mcuh, that would be great.
Would be interesting to see how to drag&drop from WPF app to another app window.
Good point Evgeny, I haven't tried this. I think it might be easier than expected since drag and drop is "global" on Windows OS.
@@SingletonSean I've tried to implement drag and drop from my app window to photoshop window. (As if I drag image from windows explorer) and it didn't work.
I've not spent much time on this, but I think it has something to do with what "datatype" other window expects.
thank you very much!
By the way, can you tell me why my rectangle can drag outside of the canvas?
Good job! Thank you for YOUR WORK👍
Hy.
Can you show a Drag&Drop-Excample for a List?
Based on your example, I would like to create these lists variably and then be able to move them among each other. In addition, it should still be possible to move the contents of the list among each other. could you show an example, please.
UserControl is not serializable, how drag drop UserControl?
When you get time, could you do a quick video on all the Extentions/SDKs/Tools you have installed in your VS2019?
I was trying to create a custom reporting tool that customers can drog and drop labels, images or draw lines and rectangles, and save the report for later use. But could not find where to start. Do you have a suggestion for me ? liked & subbed
A builder tool?
@@feitan8745 yes you are correct
great tutorials but when i try to move my box to the right it wont move it only let me move to left and bottom, fix?
Thank you - without this tutorial I would have backed out of drag&drop entirely!
Glad it was helpful Shai! Drag & drop just sounds so scary at first haha
is there any possiblitiy of doing this without XAML?
I can't get errverr how easy this was
😂😂😂😂
Thank you Sir for your Tutorial... it's really awesome and so helpful... :) :)
can you you make some tutorial about how to customize a GridView and make it with awesome look and functions.?
awesome video loved it :D
Would you implement 64 of those boxes to make a chess game? I think this would be pretty tedious... any suggestions? I am new to WPF
I imagine it would be something like that! I feel like this wouldn't be that crazy to create, but would certainly be somewhat difficult.
I've actually done 2 drag and drop projects in the past that are related to this. The drag and drop is the easy part, but the hard part is enforcing a "grid" structure that the draggable pieces will snap to. Since I have some experience with this and some old source code, I'd love to do a video on the "grid" behavior. It's super satisfying too, hahah.
Thanks for bringing up this topic!
GREAT JOB
Thanks mike!
Thank you Sir!
Note: Set playback speed to .75 for human speed.
👽👽👽
Doesn't work with tree view items.
THANKS
This seems to be useful information, but you chatter as if two people with whips are urging you on behind your back.