Setting Up Drag Drop - WPF DRAG DROP TUTORIAL #1

Поділитися
Вставка
  • Опубліковано 16 гру 2024

КОМЕНТАРІ • 46

  • @boukriabdelkhalek6855
    @boukriabdelkhalek6855 3 роки тому +2

    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.

    • @SingletonSean
      @SingletonSean  3 роки тому

      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.

    • @boukriabdelkhalek6855
      @boukriabdelkhalek6855 3 роки тому

      @@SingletonSean I will check it after all :D

  • @tjzIsMe
    @tjzIsMe 3 роки тому +2

    Thanks for this! Wonderful timing too, I was just about to tackle this in my project! Appreciate your videos!

  • @PanCave
    @PanCave 2 роки тому +4

    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?

    • @PanCave
      @PanCave 2 роки тому +1

      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

    • @Brianboy9494
      @Brianboy9494 2 роки тому +1

      @@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.

  • @Tyronblade
    @Tyronblade 3 роки тому +1

    Great stuff thanks a lot! Ill be eagerly awaiting a video covering listview 😉

    • @SingletonSean
      @SingletonSean  3 роки тому +1

      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.

  • @maxgdh7618
    @maxgdh7618 Рік тому +4

    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

    • @SpellMenderDev
      @SpellMenderDev Рік тому +2

      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.

  • @cyrildouglas9262
    @cyrildouglas9262 3 роки тому +4

    Do you plan to show the ways to implement this using MVVM?

  • @mortuusars
    @mortuusars 3 роки тому +3

    Would be interesting to see how to drag&drop from WPF app to another app window.

    • @SingletonSean
      @SingletonSean  3 роки тому

      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.

    • @mortuusars
      @mortuusars 3 роки тому

      @@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.

  • @SangTruongITE
    @SangTruongITE 2 роки тому

    thank you very much!
    By the way, can you tell me why my rectangle can drag outside of the canvas?

  • @EcuTester
    @EcuTester Рік тому +1

    Good job! Thank you for YOUR WORK👍

  • @matthiasmerz86
    @matthiasmerz86 3 роки тому +1

    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.

  • @JarosawPietras
    @JarosawPietras 3 роки тому +2

    UserControl is not serializable, how drag drop UserControl?

  • @GuildOfCalamity
    @GuildOfCalamity 3 роки тому

    When you get time, could you do a quick video on all the Extentions/SDKs/Tools you have installed in your VS2019?

  • @minimalcoder3236
    @minimalcoder3236 3 роки тому +1

    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

  • @RGBA
    @RGBA 3 роки тому

    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?

  • @shaihulud4515
    @shaihulud4515 3 роки тому

    Thank you - without this tutorial I would have backed out of drag&drop entirely!

    • @SingletonSean
      @SingletonSean  3 роки тому

      Glad it was helpful Shai! Drag & drop just sounds so scary at first haha

  • @John-vv7ok
    @John-vv7ok 2 роки тому

    is there any possiblitiy of doing this without XAML?

  • @TuberTugger
    @TuberTugger 2 роки тому +1

    I can't get errverr how easy this was

  • @elkhayyat85
    @elkhayyat85 3 роки тому

    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.?

  • @y4ni608
    @y4ni608 2 роки тому

    awesome video loved it :D

  • @DerEddieLoL
    @DerEddieLoL 3 роки тому

    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

    • @SingletonSean
      @SingletonSean  3 роки тому +1

      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!

  • @mikefocal5770
    @mikefocal5770 3 роки тому

    GREAT JOB

  • @technics6215
    @technics6215 2 роки тому

    Thank you Sir!

  • @gary6212
    @gary6212 10 місяців тому

    Note: Set playback speed to .75 for human speed.

  • @scproinc
    @scproinc 2 роки тому

    Doesn't work with tree view items.

  • @leonhardolaye-felix8811
    @leonhardolaye-felix8811 2 роки тому

    THANKS

  • @evgeniilewicki5874
    @evgeniilewicki5874 5 місяців тому

    This seems to be useful information, but you chatter as if two people with whips are urging you on behind your back.