Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Question] Drag&Drop from Toolbox #81

Closed
jpk6789 opened this issue Jan 9, 2024 · 8 comments · Fixed by #82
Closed

[Question] Drag&Drop from Toolbox #81

jpk6789 opened this issue Jan 9, 2024 · 8 comments · Fixed by #82
Assignees
Labels
question Further information is requested

Comments

@jpk6789
Copy link
Contributor

jpk6789 commented Jan 9, 2024

Hi, first of all thank you for this amazing node editor and all your work :)

I recently started to reimplement an existing XNA based node editor in WPF using nodify. However, we currently have a toolbox with applicable nodes in it and can drag&drop those nodes to the editor. I wonder how to realize such a drag&drop action of nodes with nodify. Is it possible and if yes how?

@jpk6789 jpk6789 added the question Further information is requested label Jan 9, 2024
@miroiu
Copy link
Owner

miroiu commented Jan 10, 2024

Hi! It should be pretty straight forward to implement using the DragDrop API provided by WPF.

The only issue I see is that the NodifyEditor.MouseLocation - which could be used to position the dropped node - may stop updating due to MouseMove events not firing anymore while dragging. To workaround this, create a subclass of NodifyEditor which exposes a method to get the coordinates inside the editor (graph) space and use it in the drop event handler to position the node (assuming you use the nuget package and don't have access to the source code, otherwise you can add this method to the NodifyEditor itself).

internal class CustomEditor : NodifyEditor
{
    /// <summary>
    /// Translates the event location to graph space coordinates (relative to the <see cref="ItemsHost" />).
    /// </summary>
    /// <param name="args">The drag event.</param>
    /// <returns>A location inside the graph</returns>
    public Point GetLocationInsideEditor(DragEventArgs args)
        => args.GetPosition(ItemsHost);
}

Depending on your requirements, you can also show a preview of the node you drag using the DragOver event.

I'll create a simple example and link it to this issue. Do you have any progress on this, any specific questions?

@miroiu
Copy link
Owner

miroiu commented Jan 10, 2024

I created the PR. Relevant files are (EditorView.xaml, EditorView.xaml.cs, NodifyEditor.cs).

Please let me know if this helps.

drag-drop

@jpk6789
Copy link
Contributor Author

jpk6789 commented Jan 11, 2024

Thank you very much for your quick response and for the PR. I looked into it and I think I understand it and can adapt it to my case. I will also try to use the DragOver event but this seems to be straightforward. I will update you with the progress.

P.S.: Yes, I use the NuGet package and have no direct access to the source code. This was the reason for my question.

@jpk6789
Copy link
Contributor Author

jpk6789 commented Feb 24, 2024

Hi,
as said, here is the update: It works :) I also have implemented the DtagOver preview and everything with control of the respective viewmodels. Thanks again for this awesome library and your support.

grafik

@miroiu
Copy link
Owner

miroiu commented Feb 24, 2024

Hi, thanks for the kind words and for the update. It's really cool that you also implemented the drag over preview. 🙂

@NguyenThangWorkAccount
Copy link

Hi @miroiu, I love your library and use it in my work. I have some trouble with this drag-and-drop function.So I cannot change the name of the OnDragNode method. If it is, isn't it better to note somewhere that it is enforced by code and you cannot change that name, which could lead to an error if tried?

@miroiu
Copy link
Owner

miroiu commented Jul 22, 2024

Hi, the code does not enforce the names of the Drag and Drop callbacks. Verify that your method's name is the same in XAML and C#.

@NguyenThangWorkAccount
Copy link

Yes, it turns out that maybe I created a user component and tried to host it in the form of a winforms application which may be the reason for this issue. Sorry for creating new issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants