Save and Load custom Controls

3 posts, 1 answers
  1. Alaa
    Alaa avatar
    27 posts
    Member since:
    Jun 2014

    Posted 26 Nov 2014 Link to this post

    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. Answer
    Zarko
    Admin
    Zarko avatar
    755 posts

    Posted 28 Nov 2014 Link to this post

    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.

     
  3. UI for WPF is Visual Studio 2017 Ready
  4. Alaa
    Alaa avatar
    27 posts
    Member since:
    Jun 2014

    Posted 01 Dec 2014 in reply to Zarko Link to this post

    It worked. Thank you very much.
Back to Top