Hello,
I'm having the following issue with the Serialization process in the diagram:
When I save the first time, it works great. (I can reload the layout several times and it works perfectly: my items go back to their saved positions)
However, if I saveLayout, then LoadLayout, the next time I'm going to call SaveLayout will fail because node is null in the GetNodeUniqueId override.
Any idea what could cause this? Thanks!
public
class
NodeViewModel : NodeViewModelBase
{
}
public
class
DiagramViewModel : SerializableGraphSourceBase<NodeViewModel, LinkViewModel>
{
public
override
string
GetNodeUniqueId(NodeViewModel node)
{
if
(node ==
null
)
return
string
.Empty;
// Should not happen (but happens on a saveLayout after a LoadLayout)
return
node.ID;
}
public
override
NodeViewModel DeserializeNode(IShape shape, SerializationInfo info)
{
NodeViewModel nodeViewModel = InternalItems.FirstOrDefault(p => p.DialogInfo.Tag == info[
"NodeUniqueIdKey"
].ToString());
if
(nodeViewModel ==
null
)
return
null
;
string
position = info[
"Position"
].ToString();
string
[] arr = position.Split(
';'
);
nodeViewModel.Position =
new
Point(
float
.Parse(arr[0], CultureInfo.InvariantCulture),
float
.Parse(arr[1], CultureInfo.InvariantCulture));
return
nodeViewModel;
}
}