예제 #1
0
        /// <summary>
        /// Create new key value panel
        /// </summary>
        /// <param name="key">key of panel</param>
        /// <param name="value">value of panel</param>
        /// <param name="parent">Add to parent and remove handler automatically if it's not null</param>
        /// <param name="restrictKey">If true, disable interaction with key</param>
        /// <returns></returns>
        private KeyValuePanel CreateKeyValuePanel(string key, string value, UIElementCollection parent = null)
        {
            var panel = new KeyValuePanel();

            panel.Data.Key   = key;
            panel.Data.Value = value;

            if (parent != null)
            {
                parent.Add(panel);
                panel.onRemoveRequested = (p) =>
                {
                    parent.Remove(p);
                };
            }

            return(panel);
        }
예제 #2
0
        private string BuildTextCollection(CollectionPanel panel, int level)
        {
            StringBuilder newText = new StringBuilder();

            for (int i = 0; i < level; ++i)
            {
                newText.Append("\t");
            }
            string indent = newText.ToString();

            newText.Clear();

            foreach (var i in panel.Data.Children)
            {
                CollectionPanel cp  = i as CollectionPanel;
                KeyValuePanel   kvp = i as KeyValuePanel;

                if (kvp != null)
                {
                    newText.Append(indent);
                    newText.Append("\"");
                    newText.Append(kvp.Data.Key);
                    newText.Append("\"\t");
                    newText.Append("\"");
                    newText.Append(kvp.Data.Value);
                    newText.Append("\"\n");
                }
                else if (cp != null)
                {
                    newText.Append(indent);
                    newText.Append("\"");
                    newText.Append(cp.Header.SelectedValue as string);
                    newText.Append("\"\n");
                    newText.Append(indent);
                    newText.Append("{\n");
                    newText.Append(BuildTextCollection(cp, level + 1));
                    newText.Append(indent);
                    newText.Append("}\n");
                }
            }
            return(newText.ToString());
        }