Hi,
I have a problem serializing and deserializing a business object, expanding on your examples:
http://www.telerik.com/help/wpf/raddiagram-howto-drag-custom-toolboxitem.html (1)
http://www.telerik.com/help/wpf/raddiagram-extensions-toolbox.html#PopulateWithCustomData (2)
Your examples work just fine (when I changed the geometry handling, because of localization issues, I think).
But when I try to add more properties, and serialize them, I get an error deserializing the objects.
After searching, I have now found this thread:
http://www.telerik.com/forums/adding-my-own-properties-into-settingspane-of-raddiagram-on-selection-of-shape (3)
In this thread, Zarko writes (in September 13th 2012):
...
"As for your second question - unfortunately at the moment the RadDiagram supports only string serialization."
I now have to ask: Is this still the case? I would expect serialization to have been handled way before now.
And if this is the case, how can I get around this? Can you come with a solution so that I can handle what I am trying in my example (see below)?
Thank you very much!
I have the full sample project as png files attached, but here is the issue from my point of view:
namespace DeserializationProblem
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
SerializationService.Default.ItemSerializing += Default_ItemSerializing;
}
void Default_ItemSerializing(object sender, SerializationEventArgs<IDiagramItem> e)
{
if (e.Entity is RadDiagramShape)
{
Geometry g = (e.Entity as RadDiagramShape).Geometry;
string g_string = GeometryParser.GetString(g);
e.SerializationInfo["MyGeometry"] = g_string;
if ((e.Entity as RadDiagramShape).DataContext is MyShape)
{
e.SerializationInfo["DataContent"] =
((e.Entity as RadDiagramShape).DataContext as MyShape).Header;
e.SerializationInfo["DataContent2"] =
((e.Entity as RadDiagramShape).DataContext as MyShape);
var test = (MyShape)e.SerializationInfo["DataContent2"]; // <- Works fine
}
}
}
private void radDiagram1_ShapeDeserialized(object sender, ShapeSerializationRoutedEventArgs e)
{
if (e.Shape as RadDiagramShape != null)
{
//SerializationInfo e_info = (SerializationInfo)e.SerializationInfo["MyGeometry"];
string e_info_string = e.SerializationInfo["MyGeometry"].ToString();
Geometry g = GeometryParser.GetGeometry(e_info_string);
(e.Shape as RadDiagramShape).Geometry = g;
(e.Shape as RadDiagramShape).Content = e.SerializationInfo["DataContent"].ToString(); // <- Works
var test = (MyShape)e.SerializationInfo["DataContent2"]; // <- Breaks
// Error: Unable to cast object of type 'System.String' to type 'DeserializationProblem.MyShape'.
// e.SerializationInfo["DataContent2"] is now a string "DeserializationProblem.MyShape"
}
}
}
}
I have a problem serializing and deserializing a business object, expanding on your examples:
http://www.telerik.com/help/wpf/raddiagram-howto-drag-custom-toolboxitem.html (1)
http://www.telerik.com/help/wpf/raddiagram-extensions-toolbox.html#PopulateWithCustomData (2)
Your examples work just fine (when I changed the geometry handling, because of localization issues, I think).
But when I try to add more properties, and serialize them, I get an error deserializing the objects.
After searching, I have now found this thread:
http://www.telerik.com/forums/adding-my-own-properties-into-settingspane-of-raddiagram-on-selection-of-shape (3)
In this thread, Zarko writes (in September 13th 2012):
...
"As for your second question - unfortunately at the moment the RadDiagram supports only string serialization."
I now have to ask: Is this still the case? I would expect serialization to have been handled way before now.
And if this is the case, how can I get around this? Can you come with a solution so that I can handle what I am trying in my example (see below)?
Thank you very much!
I have the full sample project as png files attached, but here is the issue from my point of view:
namespace DeserializationProblem
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
SerializationService.Default.ItemSerializing += Default_ItemSerializing;
}
void Default_ItemSerializing(object sender, SerializationEventArgs<IDiagramItem> e)
{
if (e.Entity is RadDiagramShape)
{
Geometry g = (e.Entity as RadDiagramShape).Geometry;
string g_string = GeometryParser.GetString(g);
e.SerializationInfo["MyGeometry"] = g_string;
if ((e.Entity as RadDiagramShape).DataContext is MyShape)
{
e.SerializationInfo["DataContent"] =
((e.Entity as RadDiagramShape).DataContext as MyShape).Header;
e.SerializationInfo["DataContent2"] =
((e.Entity as RadDiagramShape).DataContext as MyShape);
var test = (MyShape)e.SerializationInfo["DataContent2"]; // <- Works fine
}
}
}
private void radDiagram1_ShapeDeserialized(object sender, ShapeSerializationRoutedEventArgs e)
{
if (e.Shape as RadDiagramShape != null)
{
//SerializationInfo e_info = (SerializationInfo)e.SerializationInfo["MyGeometry"];
string e_info_string = e.SerializationInfo["MyGeometry"].ToString();
Geometry g = GeometryParser.GetGeometry(e_info_string);
(e.Shape as RadDiagramShape).Geometry = g;
(e.Shape as RadDiagramShape).Content = e.SerializationInfo["DataContent"].ToString(); // <- Works
var test = (MyShape)e.SerializationInfo["DataContent2"]; // <- Breaks
// Error: Unable to cast object of type 'System.String' to type 'DeserializationProblem.MyShape'.
// e.SerializationInfo["DataContent2"] is now a string "DeserializationProblem.MyShape"
}
}
}
}