Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Copy and Paste Not Working With Custom Diagram Class (Read 1661 times)
lrhudson
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 1
Joined: Aug 21st, 2013
Copy and Paste Not Working With Custom Diagram Class
Aug 21st, 2013 at 10:29am
Print Post  
Hi

I am having great problems trying to implement a copy and paste feature for a WPF diagramming custom object.

    [Serializable]
    internal class TranslateFunctionNode : FunctionNode
    {
        ...
        public override DiagramItem Clone(bool clipboard)
        {
            DiagramItem item = base.Clone(clipboard);

            return item;
            //return base.Clone(clipboard);
        }
    
protected override void SaveToXml(System.Xml.XmlElement xmlElement, XmlPersistContext context)
        {
            base.SaveToXml(xmlElement, context);

            context.WriteString(FunctionName, ElementFunctionName, xmlElement);
            context.WriteInt(TemplateID, ElementTemplateID, xmlElement);
            context.WriteString(TemplateName, ElementTemplateName, xmlElement);
        }

        protected override void LoadFromXml(System.Xml.XmlElement xmlElement, XmlPersistContext context)
        {
            base.LoadFromXml(xmlElement, context);

            FunctionName = context.ReadString(ElementFunctionName, xmlElement);
            TemplateID = context.ReadInt(ElementTemplateID, xmlElement);
            TemplateName = context.ReadString(ElementTemplateName, xmlElement);

            Description = CreateDescription(TemplateID, TemplateName);
        }
...


    [Serializable]
    public abstract class FunctionNode : TemplatedNode
    {

I have tried calling CopySelection and PasteSelection and CopyToClipboard/PasteFromClipboard methods but none seem to work.  No exceptions are raised but the clone method returns null and the SaveToXML method is not called on copy.

I have marked all classes as serializable and have called:
Diagram.RegisterItemClass(typeof(FunctionNode), "FunctionNode", 0);

            Diagram.RegisterItemClass(typeof(TranslateFunctionNode), "TranslationFunctionNode", 0);

in the Xaml.cs constructor.

Any ideas?  Finding this very frustrating!!!

Thanks

Lee
  
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Copy and Paste Not Working With Custom Diagram Class
Reply #1 - Aug 21st, 2013 at 10:43am
Print Post  
Hi,

TranslateFunctionNode.Clone() should return a TranslateFunctionNode instance, and not one of the base class. That should happen automatically if your class has a copy constructor: Clone calls it automatically via reflection. So you should either define a copy constructor, or create a TranslateFunctionNode in the Clone override and copy its properties from current object.

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint