Posted 15 years ago
by Andreas Boerzel
-
Software Architect,
REALTECH Software Products GmbH
Version: 9.2.0514
I want to serialize and deserialize the layout of a DockSite that contains dynamically created ToolWindows using the DockSiteLayoutSerializer. The serialization works fine, but the deserialization does not work as expected!
Code snipped:Does anyone have an idea??
Thaks Andreas
Code snipped:
public partial class GroupPanel : ToolWindow, ITimerange, INotifiyTimerangeChanged
{
. . .
}
public class PanelLayout
{
private string _layout;
[XmlAttribute()]
public string Layout
{
get
{
return _layout;
}
set
{
_layout = value;
}
}
}
public partial class Dashboard : DocumentWindow, ITimerange, INotifiyTimerangeChanged
{
public void Save()
{
XmlDocument xmlDasboard = new XmlDocument();
XmlNode xmlDashboardNode = xmlDasboard.CreateElement("Dashboard");
XmlAttribute attrDashboardName = xmlDasboard.CreateAttribute("Name");
attrDashboardName.Value = this.Title;
xmlDashboardNode.Attributes.Append(attrDashboardName);
XmlAttribute attrDashboardVersion = xmlDasboard.CreateAttribute("Version");
attrDashboardVersion.Value = "1.0";
xmlDashboardNode.Attributes.Append(attrDashboardVersion);
xmlDasboard.AppendChild(xmlDashboardNode);
XmlNode xmlLayoutNode = xmlDasboard.CreateElement("Layout");
if (_layoutSerializer == null)
{
_layoutSerializer = new DockSiteLayoutSerializer();
}
_layoutSerializer.CustomTypes.Add(typeof(PanelLayout)); // Register the custom data type
_layoutSerializer.ObjectSerializedHandler = new EventHandler<ItemSerializationEventArgs>(OnObjectSerialized);
xmlLayoutNode.InnerXml = _layoutSerializer.SaveToString(_dockSite);
xmlDashboardNode.AppendChild(xmlLayoutNode);
xmlDasboard.Save(@"c:\temp\dashboard.xml");
}
public void Load()
{
XmlDocument xmlDasboard = new XmlDocument();
xmlDasboard.Load(@"c:\temp\dashboard.xml");
XmlNode dashboard = xmlDasboard.SelectSingleNode("//Dashboard");
string version = dashboard.Attributes["Version"].Value;
if (version != "1.0")
{
return;
}
for (int n = _workspace.ToolWindows.Count - 1; n >= 0; n--)
{
ToolWindow window = _workspace.ToolWindows[n];
window.Destroy();
}
Title = dashboard.Attributes["Name"].Value;
XmlNode layout = xmlDasboard.SelectSingleNode("//Dashboard/Layout");
if (_layoutSerializer == null)
{
_layoutSerializer = new DockSiteLayoutSerializer();
}
_layoutSerializer.CustomTypes.Add(typeof(PanelLayout)); // Register the custom data type
_layoutSerializer.ObjectDeserializedHandler = new EventHandler<ItemSerializationEventArgs>(OnObjectDeserialized);
_layoutSerializer.CanLoadToolWindowTitles = true;
_layoutSerializer.LoadFromString(layout.InnerXml, _dockSite);
}
private void OnObjectSerialized(object sender, ItemSerializationEventArgs e)
{
if (e.Node is XmlDockSiteLayout)
{
}
else if (e.Node is XmlToolWindow)
{
GroupPanel panel = e.Item as GroupPanel;
PanelLayout layout = new PanelLayout();
layout.Layout = panel.GetLayout();
e.Node.Tag = layout;
}
}
private void OnObjectDeserialized(object sender, ItemSerializationEventArgs e)
{
if (e.Node is XmlDockSiteLayout)
{
}
else if (e.Node is XmlToolWindow)
{
<b>=> This code is never called!!!</b>
GroupPanel panel = new GroupPanel(this, _dockSite);
PanelLayout layout = e.Node.Tag as PanelLayout;
panel.RestoreLayout(layout.Layout);
}
}
}
Thaks Andreas