This is a migrated thread and some comments may be shown as answers.

Save and Load custom Controls

2 Answers 189 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Alaa
Top achievements
Rank 1
Alaa asked on 26 Nov 2014, 12:42 PM
1- What I have:
I applied same example in here http://www.telerik.com/help/wpf/raddiagram-extensions-toolbox.html
But, the content of myShape is an image (I dnt have a geometry) when I drop it into RadDiagram it generates new instance of one of my custom classes in deserialization. I'm doing that by serializing the Header which is the hint key for me in deserializtion for generating the right custom class for the dropped shape.
my Events:
void diagram_ShapeSerialized(object sender, SerializationEventArgs<IDiagramItem> e)
        {
            var shape = e.Entity as RadDiagramShape;
            if (shape != null)
            {
                var myShape = shape.DataContext as GalleryItem;                                              
                if (myShape != null)
                {
                        e.SerializationInfo["DataContent"] = myShape.Header;
                }
             }
}

        private void RadDiagram_ShapeDeserialized(object sender, ShapeSerializationRoutedEventArgs e)
        {
            var shape = e.Shape as RadDiagramShape;
            if (shape != null)
            {
                shape.Content = e.SerializationInfo["DataContent"].ToString();
                switch (shape.Content.ToString())
                {
                    //Charts
                    case "TimeChart":
                      shape.Content = new MyTimeChart(); break;

                    case "ValueChart":
                      shape.Content = new MyTimeValue(); break;
                   //...etc
                }
               }
             }

2- What I need:
When I save the Diagram by owner.fileManager.SaveToFile(); 
I can't find inside the xml file the Content property or any SerializationInfo that's mean nothing could be serialized! I added this line 
e.SerializationInfo["Content"] = myShape.Header;

in Serialization Event and still the same

I need to retrieve the same Design the user will make!

In Debug mode, Saving  doesn't hit the Serialization Event >>> that's mean it depends on the first serialization!
While it hits DeSerialization Event when I'm dropping the shape and when I'm loading the xml
And in Loading file time It always breaks inside DeSerialization Event at 
                shape.Content = e.SerializationInfo["DataContent"].ToString();<br>                shape.Content = e.SerializationInfo["Content"].ToString();

and says "Object reference not set to an instance of an object"!

I need help! I thought a loooot of solutions but I nothings worked! Reply me please ASAP!
Thank you.

2 Answers, 1 is accepted

Sort by
0
Accepted
Zarko
Telerik team
answered on 28 Nov 2014, 10:41 AM
Hi Alaa,
From what I could see you're handling the default serialization service's ItemSerializing event which is called when you drag an item from the toolbox, but for the diagram save you need its own event - ShapeSerialized:
<telerik:RadDiagram x:Name="diagram" ShapeSerialized="OnDiagramShapeSerialized" ShapeDeserialized="OnDiagramShapeDeserialized">
I've attached a sample project with both events so could you please examine it and tell us if it helps you.
We're looking forward to hearing from you again. 

Regards,
Zarko
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Alaa
Top achievements
Rank 1
answered on 01 Dec 2014, 11:12 AM
It worked. Thank you very much.
Tags
Diagram
Asked by
Alaa
Top achievements
Rank 1
Answers by
Zarko
Telerik team
Alaa
Top achievements
Rank 1
Share this question
or