private void filed_changed(object sender, SelectionChangedEventArgs e)
        {
            var controlop  = new ControlAndOperator();
            var pinfo      = field_cb.SelectedValue as PropertyInfo;
            var ctlcontext = new FormItemContext(_type, pinfo);

            controlop.InputControl = InputControlBuilder.CreateControl(ctlcontext);
            if (pinfo.PropertyType.Name.Equals("string", StringComparison.OrdinalIgnoreCase))
            {
                controlop.UseStringOperator = true;
            }
            else
            {
                controlop.UseNumberOperator = true;
            }

            if (CreateControlCallback != null)
            {
                controlop = CreateControlCallback(ctlcontext, controlop);
            }

            _bindobject = Activator.CreateInstance(_type);
            controlop.InputControl.DataContext = _bindobject;
            input_br.Child = controlop.InputControl;

            operator_cb.ItemsSource = null;
            if (controlop.UseStringOperator)
            {
                operator_cb.ItemsSource = EnumNameValuePair.EnumToList(typeof(StringOperator));
            }
            else if (controlop.UseNumberOperator)
            {
                operator_cb.ItemsSource = EnumNameValuePair.EnumToList(typeof(NumberOperator));
            }

            operator_cb.SelectedIndex = 0;

            if (pinfo.PropertyType.IsEnum)
            {
                operator_cb.IsEnabled = false;
            }
            else
            {
                operator_cb.IsEnabled = true;
            }
        }
示例#2
0
        public override FrameworkElement CreateControl(FormItemContext context)
        {
            ComboBox cb       = new ComboBox();
            var      enumtype = context.PropertyInfo.PropertyType;
            var      source   = EnumNameValuePair.EnumToList(enumtype);

            cb.ItemsSource       = source;
            cb.SelectedValuePath = "Value";

            var binding = new Binding(context.PropertyInfo.Name)
            {
                Mode = BindingMode.TwoWay,
            };

            binding.ValidationRules.Add(new AnnotationValidationRule(context.PropertyInfo));
            cb.SetBinding(ComboBox.SelectedValueProperty, binding);
            CustomValidation.SetValidationProperty(cb, ComboBox.SelectedValueProperty);
            StyleHelper.ApplyStyle(cb, FormControlConstrants.EDIT_COMBO_STYLE);
            return(cb);
        }
        void Initialize(Type datatype)
        {
            var logiclist = EnumNameValuePair.EnumToList(typeof(Logical));

            logic_cb.ItemsSource = logiclist;
            if (IsFirstRow)
            {
                logic_cb.IsEnabled = false;
            }
            else
            {
                logic_cb.IsEnabled     = true;
                logic_cb.SelectedIndex = 0;
            }

            var proplist = PropertyNameValuePair.TypeToList(datatype);

            if (DetermineFieldCallback != null)
            {
                proplist = DetermineFieldCallback(datatype, proplist);
            }
            field_cb.ItemsSource   = proplist;
            field_cb.SelectedIndex = 0;
        }