예제 #1
0
        private String GetValueFromUI(FieldValue value, UIElement elem)
        {
            String val = null;

            switch (value.field.type)
            {
            case Field.FIELD_TYPE.MultiItem:
            case Field.FIELD_TYPE.MultiItemSort:
                ListBox listBox = (elem as ListBox);
                val = "";
                foreach (Object obj in listBox.Items)
                {
                    if (listBox.SelectedItems.Contains(obj) == false)
                    {
                        continue;
                    }
                    Field.FieldOption opt2 = obj as Field.FieldOption;
                    if (opt2 != null)
                    {
                        if (!String.IsNullOrEmpty(val))
                        {
                            val += ",";
                        }
                        val += opt2.value;
                    }
                }
                break;

            case Field.FIELD_TYPE.Int:
            case Field.FIELD_TYPE.String:
                val = ((TextBox)elem).Text;
                break;

            case Field.FIELD_TYPE.Password:
                val = ((PasswordBox)elem).Password;
                break;

            case Field.FIELD_TYPE.Bool:
                val = (((CheckBox)elem).IsChecked == true) ? "true" : "false";
                break;

            case Field.FIELD_TYPE.Combo:
                Field.FieldOption opt = ((ComboBox)elem).SelectedItem as Field.FieldOption;
                if (opt != null)
                {
                    val = opt.value;
                }
                break;
            }
            return(val);
        }
예제 #2
0
        private UIElement CreateElementValuer(FieldValue value)
        {
            Control ret = null;

            switch (value.field.type)
            {
            case Field.FIELD_TYPE.Int:
                TextBox ibox = new TextBox();
                ibox.Text  = value.value;
                ibox.Width = 50;
                ret        = ibox;
                break;

            case Field.FIELD_TYPE.MultiItem:
            case Field.FIELD_TYPE.MultiItemSort:
                ListBox listBox = new ListBox();
                listBox.SelectionMode = SelectionMode.Multiple;
                if (value.field.type == Field.FIELD_TYPE.MultiItemSort)
                {
                    CreateSortableContextMenu(listBox);
                }
                listBox.Height = 100;
                listBox.Width  = 190;
                String[] vals = value.value.Split(',');
                foreach (String val in vals)
                {
                    Field.FieldOption opt = Field.FieldOption.GetByValue(value.field.options, val);
                    if (opt != null)
                    {
                        listBox.Items.Add(opt);
                        listBox.SelectedItems.Add(opt);
                    }
                }
                foreach (Field.FieldOption option in value.field.options)
                {
                    if (value.field.Validator != null && !String.IsNullOrEmpty(value.field.Validator(option.value)))
                    {
                        continue;
                    }
                    if (listBox.Items.Contains(option))
                    {
                        continue;
                    }
                    listBox.Items.Add(option);
                }
                ret = listBox;
                break;

            case Field.FIELD_TYPE.String:
                TextBox box = new TextBox();
                box.Text  = value.value;
                box.Width = 200;
                ret       = box;
                break;

            case Field.FIELD_TYPE.Password:
                PasswordBox pbox = new PasswordBox();
                pbox.Password = value.value;
                pbox.Width    = 200;
                ret           = pbox;
                break;

            case Field.FIELD_TYPE.Bool:
                CheckBox cbox = new CheckBox();
                cbox.IsChecked = (value.value == "true");
                ret            = cbox;
                break;

            case Field.FIELD_TYPE.Combo:
                ComboBox comboBox = new ComboBox();
                foreach (Field.FieldOption option in value.field.options)
                {
                    if (value.field.Validator == null || String.IsNullOrEmpty(value.field.Validator(option.value)))
                    {
                        comboBox.Items.Add(option);
                    }
                }
                comboBox.SelectedItem = Field.FieldOption.GetByValue(value.field.options, value.value);
                if (comboBox.SelectedIndex == -1)
                {
                    comboBox.SelectedIndex = 0;
                }
                ret = comboBox;
                break;
            }
            AutomationProperties.SetName(ret, value.field.display_name);
            return(ret);
        }