Beispiel #1
0
 public JsonTreeViewItem()
 {
     this.Header     = new JsonTreeViewItemHeader();
     this.Name       = "tvi_" + number_json_tvi++;
     this.AllowDrop  = true;
     this.IsExpanded = true;
 }
Beispiel #2
0
        static void convertToJToken_recursive(JsonTreeViewItem tvi_cur, JObject jobj_cur)
        {
            if (tvi_cur == null || jobj_cur == null)
            {
                return;
            }

            JToken cur_jtok = jobj_cur;

            // 여기서부터는 property 로 시작
            foreach (var v in tvi_cur.Items)
            {
                JsonTreeViewItem tvi_child = v as JsonTreeViewItem;
                if (tvi_child == null)
                {
                    continue;
                }

                JsonTreeViewItemHeader pan = tvi_child.Header as JsonTreeViewItemHeader;
                if (pan == null)
                {
                    continue;
                }

                // pan(MyTreeViewItem.Header) = key, val or val.type, button
                JsonTextBox tb_key      = pan.Children[0] as JsonTextBox;
                ValuePanel  panel_value = pan.Children[1] as ValuePanel;

                switch (panel_value.type)
                {
                case JTokenType.Object:
                {
                    JObject   jobj  = new JObject();
                    JProperty jprop = new JProperty(tb_key.Text, jobj);
                    (cur_jtok as JObject).Add(jprop);
                    convertToJToken_recursive(tvi_child, jobj);
                }
                break;

                case JTokenType.Array:
                {
                    JArray    jarr  = new JArray();
                    JProperty jprop = new JProperty(tb_key.Text, jarr);
                    (cur_jtok as JObject).Add(jprop);
                    for (int i = 0; i < tvi_child.Items.Count; i++)
                    {
                        JObject jobj = new JObject();
                        jarr.Add(jobj);
                        convertToJToken_recursive(tvi_child.Items[i] as JsonTreeViewItem, jobj);
                    }
                }
                break;

                default:
                {
                    JProperty jprop = new JProperty(tb_key.Text, new JValue(panel_value.value));
                    (cur_jtok as JObject).Add(jprop);
                }
                break;
                }
            }
        }