Ejemplo n.º 1
0
        public override void SetGroupedProperty(PropertyInfo property)
        {
            var attributes = property.GetAttributes <AutoFormsAttribute>();

            var attribute = GetFilteredAttribute(_config.Filter, attributes);

            if (attribute == null)
            {
                Debug.WriteLine($"ControlGroup.SetGroupedProperty - unable to create filtered control of name: {property.Name}");
                return;
            }

            var config = new ControlConfig(
                _config.LayoutHorizontalPercentage,
                attribute,
                _config.LabelStyle,
                _config.EditorStyle,
                _config.SeparatorColor,
                property,
                _config.Filter);

            var v = CreateControl(config);

            if (v == null)
            {
                Debug.WriteLine($"ControlGroup.SetGroupedProperty - unable to create control of name: {property.Name}");
                return;
            }

            Groups.Add(v);

            v.Initialize();

            _controlGrid.RowDefinitions.Add(new RowDefinition {
                Height = GridLength.Auto
            });

            Grid.SetRow(v, _controlGrid.RowDefinitions.Count - 1);
            _controlGrid.Children.Add(v);
        }
Ejemplo n.º 2
0
        public override void SetGroupedProperty(PropertyInfo property)
        {
            var attributes = property.GetAttributes <AutoFormsAttribute>();

            var attribute = GetFilteredAttribute(_config.Filter, attributes);

            if (attribute == null)
            {
                Debug.WriteLine($"ControlHorizontalGroup.SetGroupedProperty - unable to create control of name: {property.Name}");
                return;
            }

            var config = new ControlConfig(
                0.5,
                attribute,
                _config.LabelStyle,
                _config.EditorStyle,
                _config.SeparatorColor,
                property,
                _config.Filter);

            AddControl(config);
        }
 public ControlDateTime(ControlConfig config) : base(config)
 {
 }
Ejemplo n.º 4
0
 public ControlGroup(ControlConfig config) : base(config)
 {
 }
Ejemplo n.º 5
0
 public ControlList(ControlConfig config) : base(config)
 {
 }
Ejemplo n.º 6
0
 public ControlCombo(ControlConfig config) : base(config)
 {
 }
 public ControlSelectButton(ControlConfig config) : base(config)
 {
 }
Ejemplo n.º 8
0
 public ControlEditor(ControlConfig config) : base(config)
 {
 }
Ejemplo n.º 9
0
 public ControlHorizontalGroup(ControlConfig config) : base(config)
 {
     _foundStar = false;
 }
 public ControlCheckbox(ControlConfig config) : base(config)
 {
 }
Ejemplo n.º 11
0
        protected void AddControl(ControlConfig config)
        {
            var item = CreateControl(config);

            if (item == null)
            {
                Debug.WriteLine($"ControlHorizontalGroup.AddControl - unable to create control of name: {config.Property.Name}");
                return;
            }

            Groups.Add(item);

            item.Initialize();

            item.LayoutRoot.Padding = new Thickness(0, 0, 0, 0);

            View control = item;

            if (string.IsNullOrEmpty(config.Label) && item.LayoutRoot.Children.Count >= 1)
            {
                control = item.LayoutRoot.Children[item.LayoutRoot.Children.Count - 1];
                item.LayoutRoot.Children.Clear();
            }

            var horizontalAttribute = GetFilteredAttribute <AutoFormsHorizontalGroupAttribute>(config.Filter, config.Property);

            if (horizontalAttribute != null)
            {
                if (horizontalAttribute.GridType == GridUnitType.Star)
                {
                    _foundStar = true;
                }

                _grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(horizontalAttribute.Value, horizontalAttribute.GridType)
                });
            }
            else
            {
                _foundStar = true;

                _grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(1, GridUnitType.Star)
                });
            }

            Grid.SetColumn(control, _grid.ColumnDefinitions.Count - 1);
            control.VerticalOptions = LayoutOptions.End;

            _grid.Children.Add(control);

            // we do this if all the grid items only have exact widths or auto, so we make a new one at the end to take up the rest of the space
            if (_foundStar == false && _grid.Children.Count - 1 == _config.Attribute.Grouped?.Length)
            {
                _grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(1, GridUnitType.Star)
                });
            }

            //_grid.DebugGrid(Color.Red);
        }
Ejemplo n.º 12
0
 public void InitializeCustom(ControlConfig config)
 {
     _config = config;
 }
Ejemplo n.º 13
0
 public ControlRadio(bool hideHeader, ControlConfig config) : base(config)
 {
     _hideHeader = hideHeader;
 }
Ejemplo n.º 14
0
 public ControlButton(ControlConfig config) : base(config)
 {
 }
Ejemplo n.º 15
0
 public ControlBase(ControlConfig config)
 {
     Groups  = new List <ControlBase>();
     _config = config;
 }
Ejemplo n.º 16
0
        protected override View CreateControl(string bindingName, Type fieldType)
        {
            if (_config.Attribute.Orientation == AutoFormsOrientation.Vertical)
            {
                return(null);
            }

            _grid = new Grid
            {
                VerticalOptions = LayoutOptions.StartAndExpand,
                RowDefinitions  =
                {
                    new RowDefinition {
                        Height = GridLength.Auto
                    },
                },
            };

            // creating a control but removing the label so we create the label grid with zero width percentage and then after remove the actual
            // label.
            var config = new ControlConfig(
                0,
                _config.Attribute,
                _config.LabelStyle,
                _config.EditorStyle,
                _config.SeparatorColor,
                _config.Property,
                _config.Filter);

            var item = CreateControl(config);

            if (item == null)
            {
                return(_grid);
            }

            item.Initialize();
            item.RemoveLabelControl();

            var control = item;

            var horizontalAttribute = GetFilteredAttribute <AutoFormsHorizontalGroupAttribute>(_config.Filter, _config.Property);

            if (horizontalAttribute != null)
            {
                if (horizontalAttribute.GridType == GridUnitType.Star)
                {
                    _foundStar = true;
                }

                _grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(horizontalAttribute.Value, horizontalAttribute.GridType)
                });
            }
            else
            {
                _foundStar = true;
                _grid.ColumnDefinitions.Add(new ColumnDefinition {
                    Width = new GridLength(1, GridUnitType.Star)
                });
            }

            Grid.SetColumn(control, _grid.ColumnDefinitions.Count - 1);
            _grid.Children.Add(control);

            //_grid.DebugGrid(Color.Red);

            return(_grid);
        }
Ejemplo n.º 17
0
        public static ControlBase CreateControl(ControlConfig config)
        {
            var attribute = config.Attribute;
            var property  = config.Property;

            ControlBase item = null;

            switch (attribute.Type)
            {
            case AutoFormsType.Group:
                item = new ControlGroup(config);
                break;

            case AutoFormsType.Custom:
                var attribCustom = property.GetAttribute <AutoFormsCustomAttribute>();
                if (attribCustom != null && string.IsNullOrEmpty(attribCustom.CustomControlType) == false)
                {
                    item = CreateCustomControl(attribCustom.CustomControlType);

                    if (item != null && item is ControlCustom customControl)
                    {
                        customControl.InitializeCustom(config);
                    }
                }
                break;

            case AutoFormsType.ActionList:
                var attribList = property.GetAttribute <AutoFormsListAttribute>();
                if (attribList != null)
                {
                    item = new ControlList(config);
                }
                break;

            case AutoFormsType.Entry:
                item = new ControlEditor(config);
                break;

            case AutoFormsType.Combo:
                item = new ControlCombo(config);
                break;

            case AutoFormsType.Checkbox:
                item = new ControlCheckbox(config);
                break;

            case AutoFormsType.Radio:
                item = new ControlRadio(false, config);
                break;

            case AutoFormsType.DateTime:
                item = new ControlDateTime(config);
                break;

            case AutoFormsType.Button:
                item = new ControlButton(config);
                break;

            case AutoFormsType.Label:
                item = new ControlLabel(config);
                break;

            case AutoFormsType.SelectButton:
                item = new ControlSelectButton(config);
                break;

            case AutoFormsType.Auto:

                var p = property.PropertyType;

                var t = Nullable.GetUnderlyingType(p);
                if (t != null)
                {
                    p = t;
                }

                switch (p)
                {
                case Type _ when p == typeof(int):
                case Type _ when p == typeof(float):
                case Type _ when p == typeof(double):
                case Type _ when p == typeof(decimal):
                case Type _ when p == typeof(string):
                    item = new ControlEditor(config);
                    break;

                case Type _ when p == typeof(DateTime):
                case Type _ when p == typeof(DateTimeOffset):
                    item = new ControlDateTime(config);
                    break;

                case Type _ when p == typeof(ICommand):
                    item = new ControlButton(config);
                    break;

                case Type _ when p == typeof(bool):
                    item = new ControlCheckbox(config);
                    break;

                case Type _ when p.IsEnum:
                    item = new ControlCombo(config);
                    break;

                case Type _ when p == typeof(object):
                    item = new ControlLabel(config);
                    break;
                }
                break;
            }

            return(item);
        }
Ejemplo n.º 18
0
 public ControlLabel(ControlConfig config) : base(config)
 {
 }