Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) Drag and drop from native HTML element to DiagramView (Read 418 times)
davel
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 28
Location: USA
Joined: Dec 3rd, 2007
Drag and drop from native HTML element to DiagramView
Mar 19th, 2026 at 6:39pm
Print Post  
Hi,
is it possible to support drag and drop from a native HTML element in component A to a DiagramView in  component B?

Component A might have a ribbon and some other elements like a toolbox with a treeview whose nodes can be dragged.

Component B would probably have just the DiagramView.

I understand DiagamView has it's own built in support for D&D, but it's been a challenge to integrate that with
"normal" D&D, or to even disable the built-it D&D in DiagramView.

-David
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3473
Joined: Oct 19th, 2005
Re: Drag and drop from native HTML element to DiagramView
Reply #1 - Mar 19th, 2026 at 8:26pm
Print Post  
Hi,

If the final result of drag-and-drop operation will be diagram nodes, consider adding prototype nodes to the ItemListView or Palette component. Please let me know if you actually need to drag custom HTML elements.

Quote:
it's been a challenge to integrate that with "normal" D&D, or to even disable the built-it D&D in DiagramView.


Set DiagramView.Behavior to DoNothing if you mean you need to disable creating / moving items using mouse.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
davel
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 28
Location: USA
Joined: Dec 3rd, 2007
Re: Drag and drop from native HTML element to DiagramView
Reply #2 - Mar 23rd, 2026 at 8:11pm
Print Post  
I might be able to get by with the palette control. I'll need to add multiple palettes to support the UI. For some, I do not need a "top level menu", so I created the category with no name (an empty string). Let me know if you think this will cause problems.

I'd like to add TableNodes to the palette instead of shape nodes, and I'd like to add a custom icon as well (instead of node.Shape = Shape.FromId" in the sample project.) Can you provide an example of how to do this?

Also, it seems the select area for the nodes within the palette is just the icon - it does not include the text. I think my users will try to select the text and not understand only the icon can be selected. Can this be changed so that a user can grab any part of the icon or name to drag the node?

  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3473
Joined: Oct 19th, 2005
Re: Drag and drop from native HTML element to DiagramView
Reply #3 - Mar 24th, 2026 at 7:57am
Print Post  
Hi David,

Quote:
For some, I do not need a "top level menu", so I created the category with no name (an empty string). Let me know if you think this will cause problems.


A single pane of the Palette is implemented using the ItemListView control (with a header added separately), so you could instantiate that one directly.

Quote:
I'd like to add TableNodes to the palette instead of shape nodes, and I'd like to add a custom icon as well (instead of node.Shape = Shape.FromId" in the sample project.) Can you provide an example of how to do this?


You could set ShapeNode.Image + Transparent = true to display a node inside Palette as an icon, and then from NodeCreated handler clear the Image and Transparent value. Loading a bitmap is shown in SpanningCells example / LoadImage method.

For TableNode, there's no Transparent property, but you could set Brush and Pen objects to ones of Transparent color and reset from NodeCreated handler. Alternatively keep using ShapeNodes as icons but replace the instance altogether with TableNode from NodeCreated handler.

See attached test project showing how you could implement drag and drop from custom UI if you prefer that approach. It shows some exceptions in console from built-in OnDrop not finding expected data, we'll fix that with small update later this week.

Quote:
Can this be changed so that a user can grab any part of the icon or name to drag the node?


Not at this time, we'll implement that in same update and publish to nuget in a few days.

Regards,
Slavcho
Mindfusion
  

CustomDrag.zip ( 311 KB | 11 Downloads )
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3473
Joined: Oct 19th, 2005
Re: Drag and drop from native HTML element to DiagramView
Reply #4 - Mar 24th, 2026 at 9:01am
Print Post  
Here's custom drag and drop that will work without showing exceptions in console. Remove OnDrop from test project attached above, and replace OnDragStart with this:

Code
Select All
async void OnDragStart(DragEventArgs e, string nodeType)
{
	var node = new ShapeNode(diagram); // or TableNode
	var draggedNode = new DraggedNode(
		node, new Size(40, 30), "");
	var nodeRef = DotNetObjectReference.Create(
		(DraggedItem)draggedNode);
	await JS.InvokeVoidAsync("setDiagramDragData", nodeRef);
}

<script>
    window.setDiagramDragData = (dotnetRef) => {
        //console.log("setDiagramDragData");
        //console.log(dotnetRef);
        window.mf_drag = dotnetRef;
    };
</script>
 



That relies on setting same internal drag data as ItemListView / Palette, and will also show the built-in drag indicators, which you could customize using HorizontalDropAlignment, VerticalDropAlignment, DragIndicatorOpacity properties.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3473
Joined: Oct 19th, 2005
Re: Drag and drop from native HTML element to DiagramView
Reply #5 - Mar 26th, 2026 at 1:28pm
Print Post  
Hi,

This build allows dragging a node from Palette / ItemListView by grabbing the label as well -

https://www.nuget.org/packages/MindFusion.Diagramming.Blazor/2.1.2-beta2

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
davel
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 28
Location: USA
Joined: Dec 3rd, 2007
Re: Drag and drop from native HTML element to DiagramView
Reply #6 - Mar 31st, 2026 at 9:20pm
Print Post  
Thanks & thanks for the sample code that supports d&d, I was able to use that to get what I needed.

I have another issue - and again it may not be related to Mindfusion code - it's hard to tell.

I'm using Syncfusion sfTab as a tab control. I have multiple tabs, each tab has a DiagramView as its content. With more than one tab open, when I resize the window, I get an exception on the page, here is some of the stack trace:

beginInvokeDotNetFromJS @ blazor.webassembly.66stpp682q.js:1
invokeDotNetMethodAsync @ blazor.webassembly.66stpp682q.js:1
invokeMethodAsync @ blazor.webassembly.66stpp682q.js:1
(anonymous) @ DiagramView.wfh7b1ik6q.razor.js:21Understand this error
blazor.webassembly.66stpp682q.js:1    at MindFusion.Diagramming.Blazor.DiagramView.OnResize(Double width, Double height)
wt @ blazor.webassembly.66stpp682q.js:1
put_char @ dotnet.native.ozqq81eg2c.js:1730


You can view the issue here:
https://vtsweb2-f7eeceekecf8g4aw.eastus2-01.azurewebsites.net/

select New->ExpertAdvisor
click the tab "diagram2"
resize the page

Thanks for any help.
-David
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3473
Joined: Oct 19th, 2005
Re: Drag and drop from native HTML element to DiagramView
Reply #7 - Apr 1st, 2026 at 8:13am
Print Post  
It seems the tabs dispose DiagramView and we'll need to detach event handlers at that point. For time being check if this helps:

Code
Select All
<SfTab LoadOn="ContentLoad.Init"> 



Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
davel
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 28
Location: USA
Joined: Dec 3rd, 2007
Re: Drag and drop from native HTML element to DiagramView
Reply #8 - Apr 1st, 2026 at 9:02pm
Print Post  
When I use ContentLoad.Init the same DiagramView object is rendered in every tab. It doesn't crash on resize, but I think that is because the single DiagramVeiw is never disposed.

It actually took a good bit of effort and refactoring to have a unique diagramView object in each tab. I save and load the diagramView data (xml string) in the tab events. This doesn't seem right/good, but it works for the time being.

This is some of my code:


<SfTab ID="Tab" LoadOn="ContentLoad.Init" EnablePersistence="true" ShowCloseButton="true" Height="100%" @ref="TabObj">
@* <SfTab ID="Tab" EnablePersistence="true" ShowCloseButton="true" Height="100%" @ref="TabObj"> *@
    <TabEvents Selected="OnTabSelected" Selecting="OnTabSelecting" Removing="OnTabRemoving"></TabEvents>
    <TabItems>
        @foreach (var tab in DynamicTabs)
        {
            var currentTab = tab; // Local capture
            <TabItem @key="currentTab.Id">
                <ChildContent>
                    <TabHeader Text="@currentTab.Title"></TabHeader>
                </ChildContent>
                <ContentTemplate>
                    <div style="height: 100%; width: 100%;">
                        <DiagramViewComponent @ref="currentTab.DiagramComponentRef" Title="@currentTab.Id" @key="@currentTab.Id" />
                    </div>
                </ContentTemplate>
            </TabItem>
        }
    </TabItems>
</SfTab>

@code {

    public class DynamicTabData
    {
        public string Id { get; set; } = Guid.NewGuid().ToString();
        public string Title { get; set; }
        public DiagramViewComponent DiagramComponentRef { get; set; }
    }

....

  private async Task OnTabSelected(SelectEventArgs args)
  {
      // args.IsInteracted is true ONLY if the user clicked the tab
      if (args.IsInteracted)
      {
          await OutputService.WriteLineAsync($"TabComponent: tab selected {args.SelectedIndex}");
          string xml = DiagramStateService.LoadDiagramFromString(args.SelectedIndex);
          if(xml != string.Empty)
          {
              DynamicTabs[args.SelectedIndex].DiagramComponentRef.GetDiagramView().Diagram.LoadFromString(xml, MindFusion.Diagramming.SaveToStringFormat.Xml);
          }
      }
  }

  private async Task OnTabSelecting(SelectingEventArgs args)
  {
      // This fires BEFORE the tab switches
      // Save the current tab's state before exiting
      var previousIndex = args.PreviousIndex;

      if (previousIndex >= 0 && previousIndex < DynamicTabs.Count)
      {
          var exitingTab = DynamicTabs[previousIndex];

          if (exitingTab?.DiagramComponentRef != null)
          {
              var diagramView = exitingTab.DiagramComponentRef.GetDiagramView();
              if (diagramView?.Diagram != null)
              {
                  // Optionally save as string for serialization
                  var diagramString = diagramView.Diagram.SaveToString(MindFusion.Diagramming.SaveToStringFormat.Xml, true);
                  DiagramStateService.SaveDiagramToString(previousIndex, diagramString);

                  await OutputService.WriteLineAsync($"TabComponent: Saved state for tab: {exitingTab.Title}");
              }
          }
      }
  }



Thanks, David
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3473
Joined: Oct 19th, 2005
Re: Drag and drop from native HTML element to DiagramView
Reply #9 - Apr 2nd, 2026 at 12:06pm
Print Post  
This build should dispose views correctly in your original scenario -

https://www.nuget.org/packages/MindFusion.Diagramming.Blazor/2.1.2-beta3

We've only tested by adding and removing diagram view dynamically in razor page. Let us know if you are still seeing problems with the SFTab specifically.

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
davel
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 28
Location: USA
Joined: Dec 3rd, 2007
Re: Drag and drop from native HTML element to DiagramView
Reply #10 - Apr 2nd, 2026 at 2:57pm
Print Post  
This works in <sfTab>, thanks!!
  
Back to top
 
IP Logged
 
davel
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 28
Location: USA
Joined: Dec 3rd, 2007
Re: Drag and drop from native HTML element to DiagramView
Reply #11 - Apr 2nd, 2026 at 5:44pm
Print Post  
As noted above, the updated library addressed the resize issue.

I'm seeing another error - it could be because I am not disposing my objects correctly, but I am not seeing anything obvious.

If I open 3 tabs, close the second, then click the last tab (to the left), I get an exception. Here is some of the stack trace:

$mono_main_thread_schedule_background_job @ dotnet.native.6o34gdipxe.wasm:0x61753
$mono_gc_finalize_notify @ dotnet.native.6o34gdipxe.wasm:0x12c169
$sgen_client_finalize_notify @ dotnet.native.6o34gdipxe.wasm:0x12f0e0
$major_do_collection @ dotnet.native.6o34gdipxe.wasm:0x67a17
$sgen_perform_collection @ dotnet.native.6o34gdipxe.wasm:0x66c5f
$sgen_ensure_free_space @ dotnet.native.6o34gdipxe.wasm:0x66a2d
$sgen_los_alloc_large_inner @ dotnet.native.6o34gdipxe.wasm:0x6e641
$sgen_alloc_obj_nolock @ dotnet.native.6o34gdipxe.wasm:0x6558b
$mono_gc_alloc_vector @ dotnet.native.6o34gdipxe.wasm:0x12fc7d
$mono_array_new_specific_internal @ dotnet.native.6o34gdipxe.wasm:0x106e7c
$mono_array_new_specific_checked @ dotnet.native.6o34gdipxe.wasm:0x106ec8
$mono_interp_exec_method @ dotnet.native.6o34gdipxe.wasm:0x2121d
$interp_runtime_invoke @ dotnet.native.6o34gdipxe.wasm:0x293c4
$mono_jit_runtime_invoke @ dotnet.native.6o34gdipxe.wasm:0x140258
$do_runtime_invoke @ dotnet.native.6o34gdipxe.wasm:0xffb94
$mono_runtime_try_invoke @ dotnet.native.6o34gdipxe.wasm:0x100614
$mono_runtime_invoke @ dotnet.native.6o34gdipxe.wasm:0x103242
$mono_wasm_invoke_jsexport @ dotnet.native.6o34gdipxe.wasm:0x80f1d2
(anonymous) @ dotnet.native.ph6hhls5xl.js:811
ccall @ dotnet.native.ph6hhls5xl.js:10133
(anonymous) @ dotnet.native.ph6hhls5xl.js:10151
kn @ managed-exports.ts:304
(anonymous) @ invoke-cs.ts:327
beginInvokeDotNetFromJS @ blazor.webassembly.66stpp682q.js:1
invokeDotNetMethodAsync @ blazor.webassembly.66stpp682q.js:1
invokeMethodAsync @ blazor.webassembly.66stpp682q.js:1
(anonymous) @ blazor.webassembly.66stpp682q.js:1
k @ blazor.webassembly.66stpp682q.js:1
(anonymous) @ blazor.webassembly.66stpp682q.js:1
invokeWhenHeapUnlocked @ blazor.webassembly.66stpp682q.js:1
(anonymous) @ blazor.webassembly.66stpp682q.js:1
k @ blazor.webassembly.66stpp682q.js:1
N @ blazor.webassembly.66stpp682q.js:1
dispatchGlobalEventToAllElements @ blazor.webassembly.66stpp682q.js:1
onGlobalEvent @ blazor.webassembly.66stpp682q.js:1Understand this error
blazor.webassembly.66stpp682q.js:1    at MindFusion.Diagramming.Blazor.DiagramView.b()
wt @ blazor.webassembly.66stpp682q.js:1
put_char @ dotnet.native.ph6hhls5xl.js:1730
write @ dotnet.native.ph6hhls5xl.js:1676
write @ dotnet.native.ph6hhls5xl.js:3454
doWritev @ dotnet.native.ph6hhls5xl.js:9339
_fd_write @ dotnet.native.ph6hhls5xl.js:9421
$__stdio_write @ dotnet.native.6o34gdipxe.wasm:0x7c9bd7
$__fwritex @ dotnet.native.6o34gdipxe.wasm:0x7ca8c0
$fwrite @ dotnet.native.6o34gdipxe.wasm:0x7ca983
$fputs @ dotnet.native.6o34gdipxe.wasm:0x7ca322
$default_stderr_handler @ dotnet.native.6o34gdipxe.wasm:0x570c9
$monoeg_g_printerr @ dotnet.native.6o34gdipxe.wasm:0x57099
$mono_print_unhandled_exception_internal @ dotnet.native.6o34gdipxe.wasm:0x105477
$ves_icall_System_Environment_FailFast @ dotnet.native.6o34gdipxe.wasm:0xcce6b
$ves_icall_System_Environment_FailFast_raw @ dotnet.native.6o34gdipxe.wasm:0xceaa4
$do_icall @ dotnet.native.6o34gdipxe.wasm:0x2bb4c
$do_icall_wrapper @ dotnet.native.6o34gdipxe.wasm:0x27b0e
$mono_interp_exec_method @ dotnet.native.6o34gdipxe.wasm:0x18d2d
$interp_entry @ dotnet.native.6o34gdipxe.wasm:0x2b0c6
$interp_entry_static_0 @ dotnet.native.6o34gdipxe.wasm:0x2d062
$wasm_native_to_interp_System_Private_CoreLib_System_Threading_ThreadPool_Backgr
oundJobHandler @ dotnet.native.6o34gdipxe.wasm:0x80cae9

  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3473
Joined: Oct 19th, 2005
Re: Drag and drop from native HTML element to DiagramView
Reply #12 - Apr 3rd, 2026 at 6:56am
Print Post  
We couldn't reproduce this. Is the same code deployed on the azure test website above, or could you attach a test project showing the error?

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
davel
YaBB Newbies
*
Offline


I love YaBB 1G - SP1!

Posts: 28
Location: USA
Joined: Dec 3rd, 2007
Re: Drag and drop from native HTML element to DiagramView
Reply #13 - Apr 3rd, 2026 at 1:27pm
Print Post  
Yes, same code is at:
https://vtsweb2-f7eeceekecf8g4aw.eastus2-01.azurewebsites.net/

Here are the steps:
New -> Expert Advisor
New -> Expert Advisor
click Diagram 3 tab
click Diagram 1 tab
close Diagram 2 tab
click Diagram 3 tab


  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3473
Joined: Oct 19th, 2005
Re: Drag and drop from native HTML element to DiagramView
Reply #14 - Apr 6th, 2026 at 6:46am
Print Post  
Hi,

The first exception we are seeing following these steps is:

Code
Select All
Microsoft.AspNetCore.Components.WebAssembly.Rendering.WebAssemblyRenderer[100]
      Unhandled exception rendering component: Arg_NullReferenceException
System.NullReferenceException: Arg_NullReferenceException
   at VtsWeb2.Components.TabComponent.OnTabSelected(SelectEventArgs args)
   at Microsoft.AspNetCore.Components.ComponentBase.CallStateHasChangedOnAsyncCompletion(Task task)
   at Syncfusion.Blazor.Navigations.SfTab.SwitchTabClick(Int32 targetIndex, SelectingEventArgs eventArgs)
   at Syncfusion.Blazor.Navigations.SfTab.OnAfterRenderAsync(Boolean firstRender)
   at Microsoft.AspNetCore.Components.RenderTree.Renderer.GetErrorHandledTask(Task , ComponentState ) 



Please check which value is null in OnTabSelected, as this exception might leave the UI in undefined state.

Our developer compared diagram's JS DOM interop code in browser debugger with the patched one from 2.1.2-beta3 package above, and it's actually an older version. Please try deleting bin and obj subfolders under the project to force a full rebuild (and then you might also have to clean browser's cache, we find Blazor code updates rather finicky otherwise).

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint