Following your Serialize a Databound Diagram article
I was wondering whether the RadDiagram Serialization/Deserialization system supports serialization of a collection within the GraphSource Nodes. In particular I am interested on using an ObservableCollection:
01.
public
class
OrgItem : HierarchicalNodeViewModel
02.
{
03.
public
OrgItem()
04.
{
05.
this
.MyCollection =
new
ObservableCollection<
string
>();
06.
}
07.
public
ObservableCollection<
string
> MyCollection
08.
{
09.
get
;
10.
}
11.
…
12.
…
13.
…
14.
}
15.
private
void
BindGraphSource()
16.
{
17.
int
uniqueIdCounter = 0;
18.
GraphSource source =
new
GraphSource();
19.
OrgItem rootItem =
new
OrgItem()
20.
{
21.
Title =
"CEO"
,
22.
Position =
new
Point(200, 20),
23.
Id = (uniqueIdCounter++).ToString()
24.
};
25.
rootItem.MyCollection.Add(
new
MyClass(“Test1”));
26.
rootItem.MyCollection.Add(
new
MyClass(“Test2”));
27.
source.AddNode(rootItem);
28.
…
29.
…
30.
…
31.
}
32.
public
class
MyClass
33.
{
34.
public
MyClass(){};
35.
public
MyClass(
string
myValue)
36.
{
37.
this
.MyValue = myValue;
38.
}
39.
public
string
MyValue {
get
;
set
; }
40.
}
Could I possibly Serialize/Deserialize the ObservableCollection in the OrgItem?
If that is possible how should i serialize/deserialize the collection in the GraphSource?
01.
public
class
GraphSource : SerializableGraphSourceBase<OrgItem, OrgLink>
02.
{
03.
public
override
string
GetNodeUniqueId(OrgItem node)
04.
{
05.
return
node.Id;
06.
}
07.
public
override
void
SerializeNode(OrgItem node,
08.
Telerik.Windows.Diagrams.Core.SerializationInfo info)
09.
{
10.
base
.SerializeNode(node, info);
11.
info[
"Title"
] = node.Title;
12.
}
13.
public
override
OrgItem DeserializeNode(
14.
Telerik.Windows.Diagrams.Core.IShape shape,
15.
Telerik.Windows.Diagrams.Core.SerializationInfo info)
16.
{
17.
base
.DeserializeNode(shape, info);
18.
if
(info[
"Title"
] !=
null
)
19.
{
20.
return
new
OrgItem(info[
"Title"
].ToString());
21.
}
22.
return
null
;
23.
}
24.
}
Many thanks in advance,
Christos