diff options
Diffstat (limited to 'src/GraphicObjects/Expandable.cs')
| -rw-r--r-- | src/GraphicObjects/Expandable.cs | 69 |
1 files changed, 14 insertions, 55 deletions
diff --git a/src/GraphicObjects/Expandable.cs b/src/GraphicObjects/Expandable.cs index 5bf535a4..369930a8 100644 --- a/src/GraphicObjects/Expandable.cs +++ b/src/GraphicObjects/Expandable.cs @@ -19,17 +19,25 @@ using System.IO; namespace go
{
[DefaultTemplate("#go.Templates.Expandable.goml")]
- public class Expandable : TemplatedControl
+ public class Expandable : TemplatedContainer
{
bool _isExpanded;
Label _caption;
Image _image;
-
- public Container Content;
+ Container _contentContainer;
public event EventHandler Expand;
public event EventHandler Collapse;
+ public override GraphicObject Content {
+ get {
+ return _contentContainer == null ? null : _contentContainer.Child;
+ }
+ set {
+ _contentContainer.SetChild(value);
+ }
+ }
+
public Expandable() : base()
{
}
@@ -38,8 +46,8 @@ namespace go {
base.loadTemplate (template);
+ _contentContainer = this.child.FindByName ("Content") as Container;
_caption = this.child.FindByName ("Caption") as Label;
- Content = this.child.FindByName ("Content") as Container;
_image = this.child.FindByName ("Image") as Image;
if (_image == null)
@@ -84,12 +92,12 @@ namespace go public virtual void onExpand(object sender, EventArgs e)
{
- Content.Visible = true;
+ _contentContainer.Visible = true;
Expand.Raise (this, e);
}
public virtual void onCollapse(object sender, EventArgs e)
{
- Content.Visible = false;
+ _contentContainer.Visible = false;
Collapse.Raise (this, e);
}
@@ -99,54 +107,5 @@ namespace go base.onMouseClick (sender, e);
}
- public override void ReadXml(System.Xml.XmlReader reader)
- {
- using (System.Xml.XmlReader subTree = reader.ReadSubtree ()) {
- subTree.Read ();
- string tmp = subTree.ReadOuterXml ();
-
- //seek for template tag
- using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) {
- xr.Read ();
- base.ReadXml (xr);
- }
- //process content
- using (XmlReader xr = new XmlTextReader (tmp, XmlNodeType.Element, null)) {
- xr.Read (); //skip current node
-
- while (!xr.EOF) {
- xr.Read (); //read first child
-
- if (!xr.IsStartElement ())
- continue;
- if (xr.Name == "Template")
- continue;
-
- Type t = Type.GetType ("go." + xr.Name);
- GraphicObject go = (GraphicObject)Activator.CreateInstance (t);
-
- (go as IXmlSerializable).ReadXml (xr);
-
- Content.SetChild (go);
-
- xr.Read (); //closing tag
- }
-
- }
- }
- }
- public override void WriteXml(System.Xml.XmlWriter writer)
- {
- base.WriteXml(writer);
-
- if (Content == null)
- return;
- if (Content.Child == null)
- return;
- //TODO: if template is not the default one, we have to save it
- writer.WriteStartElement(Content.Child.GetType().Name);
- (Content.Child as IXmlSerializable).WriteXml(writer);
- writer.WriteEndElement();
- }
}
}
|