Beispiel #1
0
        public override object ConvertTo(ITypeDescriptorContext context,
                                         CultureInfo culture,
                                         object value,
                                         Type destinationType)
        {
            if (!(value is TableLayoutSettings) || destinationType != typeof(string))
            {
                return(base.ConvertTo(context, culture, value, destinationType));
            }

            TableLayoutSettings settings = value as TableLayoutSettings;
            StringWriter        sw       = new StringWriter();
            XmlTextWriter       xw       = new XmlTextWriter(sw);

            xw.WriteStartDocument();
            List <ControlInfo> list = settings.GetControls();

            xw.WriteStartElement("TableLayoutSettings");
            xw.WriteStartElement("Controls");

            foreach (ControlInfo info in list)
            {
                xw.WriteStartElement("Control");
                xw.WriteAttributeString("Name", info.Control.ToString());
                xw.WriteAttributeString("Row", info.Row.ToString());
                xw.WriteAttributeString("RowSpan", info.RowSpan.ToString());
                xw.WriteAttributeString("Column", info.Col.ToString());
                xw.WriteAttributeString("ColumnSpan", info.ColSpan.ToString());
                xw.WriteEndElement();
            }
            xw.WriteEndElement();


            List <string> styles = new List <string> ();

            foreach (ColumnStyle style in settings.ColumnStyles)
            {
                styles.Add(style.SizeType.ToString());
                styles.Add(style.Width.ToString(CultureInfo.InvariantCulture));
            }


            xw.WriteStartElement("Columns");
            xw.WriteAttributeString("Styles", String.Join(",", styles.ToArray()));
            xw.WriteEndElement();

            styles.Clear();
            foreach (RowStyle style in settings.RowStyles)
            {
                styles.Add(style.SizeType.ToString());
                styles.Add(style.Height.ToString(CultureInfo.InvariantCulture));
            }

            xw.WriteStartElement("Rows");
            xw.WriteAttributeString("Styles", String.Join(",", styles.ToArray()));
            xw.WriteEndElement();

            xw.WriteEndElement();
            xw.WriteEndDocument();
            xw.Close();

            return(sw.ToString());
        }