Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic CopyToClipboard / PasteFromClipboard with DiagramItem Tags (Read 538 times)
nyctophilia
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 4
Joined: Dec 17th, 2025
CopyToClipboard / PasteFromClipboard with DiagramItem Tags
Dec 17th, 2025 at 8:56am
Print Post  
Hi,

I am currently trying to use CopyToClipboard / PasteFromClipboard on DiagramItems which are selected in my DiagramView. Currently using .NET Core 8 with the latest Mindfusion version.

The DiagramItems itself can be copy/pasted, however, what gets lost along the way is the Tag, which is being set to null after pasting. The Tag is a custom object class, which I assume is not being serialized correctly. What do I have to do in order to correctly copy/paste the items Tag?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: CopyToClipboard / PasteFromClipboard with DiagramItem Tags
Reply #1 - Dec 17th, 2025 at 9:15am
Print Post  
Hi,

Tag are saved automatically if their types are marked as [Serializable]. However that relies on BinaryFormatter, which is now obsolete. You can still use it in dotnet 8 by adding a project flag:

https://learn.microsoft.com/en-us/answers/questions/2259767/how-can-i-use-binary...

Dotnet 10 dropped BinaryFormatter altogether and we'll be migrating diagram's clipboard storage to XML format instead for upcoming release.

Alternatively, if you don't need to copy and paste between different processes but only current one, you could use CopySelection / PasteSelection methods instead.

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


I Love MindFusion!

Posts: 4
Joined: Dec 17th, 2025
Re: CopyToClipboard / PasteFromClipboard with DiagramItem Tags
Reply #2 - Dec 17th, 2025 at 9:36am
Print Post  
Thanks! I will take a look into it
  
Back to top
 
IP Logged
 
nyctophilia
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 4
Joined: Dec 17th, 2025
Re: CopyToClipboard / PasteFromClipboard with DiagramItem Tags
Reply #3 - Dec 17th, 2025 at 9:53am
Print Post  
I added the [Serializable] decorators to the necessary classes and added the flag to the project. Now it looks like not even the DiagramItems are copied anymore.. However, I marked some of the custom class fields with [NonSerialized] since I do not want to serialize everything. Would that be the problem?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: CopyToClipboard / PasteFromClipboard with DiagramItem Tags
Reply #4 - Dec 17th, 2025 at 11:24am
Print Post  
Adding this to Samples.Net8/SiteMap sample project seems to work correctly in my test:

Code
Select All
rootNode.Selected = true;

siteMapView.CopyToClipboard(true);
for (int i = 1; i < 4; i++)
    siteMapView.PasteFromClipboard(10 * i, 10 * i);
foreach (var node in siteMap.Nodes)
    if (node.Tag is PageProps pprops)
        Debug.WriteLine(pprops.title); 



Maybe check if some of the serializable fields from your tag type don't refer to another type that should be marked too. Also verify there aren't any exceptions reported if you enable the 'stop when thrown' option in VS' exceptions window (Ctrl+Alt+E) as clipboard methods do catch exceptions internally.

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


I Love MindFusion!

Posts: 4
Joined: Dec 17th, 2025
Re: CopyToClipboard / PasteFromClipboard with DiagramItem Tags
Reply #5 - Dec 18th, 2025 at 10:10am
Print Post  
Hi Slavcho,

I solved the problem when I added the serialization constructors to my classes, e.g.

Code
Select All
protected ClassName(SerializationInfo info, StreamingContext context)
{
     Id = info.GetString("Id");
}
 



It took a while to find out because there was not exception thrown although I enabled to throw any exceptions.

Besides, can you tell when the release with replacing the BinaryFormatter serialization will happen?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3435
Joined: Oct 19th, 2005
Re: CopyToClipboard / PasteFromClipboard with DiagramItem Tags
Reply #6 - Dec 18th, 2025 at 10:53am
Print Post  
Hi,

Try this build -

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

It adds an XmlClipboard property we have in other platforms. XmlClipboard is enabled by default.

New version also includes Tag serialization changes from this thread:

https://mindfusion.dev/Forum/YaBB.pl?num=1763378580

where Tag objects are saved using XmlSerializer or JsonSerializer in respective formats instead of BinaryFormatter.

We should release it next week.

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