예제 #1
0
 public static object GetDropDownValue(InputTypeAttribute inputAttribute, PropertyInfo p, ContentProperty propertyPost)
 {
     if (inputAttribute == null || propertyPost == null)
     {
         return(null);
     }
     if (!inputAttribute.MultiSelect)
     {
         return(propertyPost.Value.MyTryConvert(p.PropertyType));
     }
     else
     {
         return(propertyPost.MultiValue.MyTryConvert(p.PropertyType));
     }
 }
예제 #2
0
        protected virtual FrameworkElement GetControlFromProperty(PropertyInfo property, Binding binding)
        {
            // check attribute on this property to determine if we use defaults
            object[]           attrs = property.GetCustomAttributes(typeof(InputTypeAttribute), false);
            InputTypeAttribute display;

            if (attrs.Length == 1)
            {
                display = (InputTypeAttribute)attrs[0];
            }
            else
            {
                display = new InputTypeAttribute()
                {
                    FormType = InputTypeAttribute.FormTypes.@default
                }
            };

            FrameworkElement control = null;

            if (display.FormType == InputTypeAttribute.FormTypes.@default)
            {
                if (property.PropertyType == typeof(bool))
                {
                    control = GenerateCheckBox(property, binding);
                }
                else if (property.PropertyType == typeof(bool?))
                {
                    control = GenerateThreeStateCheckBox(property, binding);
                }
                else
                {
                    NullableContentWrapper wrp = null;
                    var type = property.PropertyType;
                    var b    = binding;
                    var tp   = Nullable.GetUnderlyingType(property.PropertyType);
                    if (tp != null || type == typeof(string))
                    {
                        wrp            = new NullableContentWrapper();
                        tp             = tp ?? typeof(string);
                        type           = tp;
                        wrp.ObjectType = type;

                        wrp.SetBinding(NullableContentWrapper.ObjectValueProperty, b);
                        b = new Binding("Value")
                        {
                            Mode = BindingMode.TwoWay, Source = wrp, ConverterCulture = CultureInfo.CurrentCulture
                        };
                        b.UpdateSourceTrigger = UpdateSourceTrigger.PropertyChanged;

                        b.ConverterCulture        = CultureInfo.CurrentCulture;
                        b.ValidatesOnDataErrors   = true;
                        b.ValidatesOnExceptions   = true;
                        b.NotifyOnValidationError = true;
                    }

                    if (type == typeof(DateTime))
                    {
                        b.Converter = WPF.DataForm.DateTimeUtcConverter.Instance.Value;
                        control     = GenerateDatePicker(property, b);
                    }
                    else if (type == typeof(DateTimeOffset))
                    {
                        b.Converter = WPF.DataForm.DateTimeOffsetConverter.Instance.Value;
                        control     = GenerateDatePicker(property, b);
                    }
                    else if (type.IsEnum)
                    {
                        control = GenerateComboBox(type, property, b);
                    }
                    else if (type == typeof(string))
                    {
                        control = GenerateWaterMarkedTextBox(property, b);
                    }
                    else if (type == typeof(byte) || type == typeof(sbyte))
                    {
                        control = GenerateIntegerUpDow(property, b);
                    }
                    else if (type == typeof(Int32) || type == typeof(UInt32))
                    {
                        control = GenerateIntegerUpDow(property, b);
                    }
                    else if (type == typeof(Int16) || type == typeof(UInt16))
                    {
                        control = GenerateShortUpDow(property, b);
                    }
                    else if (type == typeof(Int64) || type == typeof(UInt64))
                    {
                        control = GenerateLongUpDown(property, b);
                    }
                    else if (type == typeof(Decimal))
                    {
                        control = GenerateDecimalUpDown(property, b);
                    }
                    else if (type == typeof(Double))
                    {
                        control = GenerateDoubleUpDown(property, b);
                    }
                    else if (type == typeof(Single))
                    {
                        control = GenerateSingleUpDown(property, b);
                    }
                    else if (type == typeof(Color))
                    {
                        control = GenerateColorPicker(property, b);
                    }
                    else
                    {
                        control = null;
                    }

                    if (tp != null)
                    {
                        wrp.contentCtl.Content = control;
                        control = wrp;

                        wrp.nullCheck.IsEnabled = (bindables[property.Name].Direction == BindingDirection.TwoWay);
                    }
                }
            }
            else
            {  // we direct the object
                switch (display.FormType)
                {
                case InputTypeAttribute.FormTypes.box:
                    control = GenerateWaterMarkedTextBox(property, binding);
                    break;

                case InputTypeAttribute.FormTypes.calculator:
                    control = GenerateCalculator(property, binding);
                    break;

                case InputTypeAttribute.FormTypes.check:
                    control = GenerateCheckBox(property, binding);
                    break;

                case InputTypeAttribute.FormTypes.dates:
                    control = GenerateDatePicker(property, binding);
                    break;

                case InputTypeAttribute.FormTypes.textArea:
                    control = GenerateMultiLineTextBox(property, binding, display.PreferredHeight);
                    break;

                default:
                    break;
                }
            }
            if (control != null)
            {
                control.HorizontalAlignment = Windows.HorizontalAlignment.Stretch;
            }
            if (display.PreferredWidth != null && control != null)
            {
                control.Width = (int)display.PreferredWidth;
            }
            return(control);
        }