예제 #1
0
        private static NXmlNode SerializeTreeViewItem(NTreeViewItem item)
        {
            NElementInfo elementInfo = (NElementInfo)item.Tag;

            if (elementInfo == null)
            {
                string text = ((NLabel)item.Header.Content).Text;
                return(new NXmlTextNode(ENXmlNodeType.Text, text));
            }

            // Create an XML element for the current tree view item
            NXmlElement element = new NXmlElement(elementInfo.Name);

            if (elementInfo.Attributes.Count > 0)
            {
                // Set the element's attributes
                INIterator <NKeyValuePair <string, string> > iter = elementInfo.Attributes.GetIterator();
                while (iter.MoveNext())
                {
                    element.SetAttribute(iter.Current.Key, iter.Current.Value);
                }
            }

            // Loop through the item's children
            for (int i = 0, childCount = item.Items.Count; i < childCount; i++)
            {
                element.AddChild(SerializeTreeViewItem(item.Items[i]));
            }

            return(element);
        }