Ejemplo n.º 1
0
        private FieldGroup GetGroup(string name)
        {
            if (string.IsNullOrEmpty(name))
            {
                name = ObjectEditor.Translate("Extra");
            }
            var ret = FieldGroups.FirstOrDefault(d => d.Name.Equals(name));

            if (ret == null)
            {
                ret = new FieldGroup()
                {
                    Name = name
                };

                ret.View = new TableSection()
                {
                    Title = name
                };

                ret.Fields = new ObservableCollection <EditableField>();
                table.Add(ret.View as TableSection);

                FieldGroups.Add(ret);
            }
            return(ret);
        }
Ejemplo n.º 2
0
        public override Element GetEditor(EditableField field, object obj)
        {
            Element view    = null;
            var     lblText = ObjectEditor.Translate(field.PropertyData.Title);
            Label   lbl     = new Label()
            {
                Text = lblText
            };

            if (view == null)
            {
                if (field.PropertyData.Readonly)
                {
                    view = new Label()
                    {
                        BindingContext = field,
                        Text           = field.Value.ToString()
                    };
                    view.SetBinding(Entry.TextProperty, nameof(field.Value));
                }
                else
                {
                    var type = field.SourceProperty.PropertyType;
                    if (type == typeof(string) || type == typeof(int))
                    {
                        view = new Entry()
                        {
                            Text = field.Value.ToString()
                        };
                        view.SetBinding(EntryCell.TextProperty, nameof(field.Value));
                    }
                    else if (type == typeof(bool))
                    {
                        view = new Switch()
                        {
                        };
                        view.SetBinding(Switch.IsToggledProperty, nameof(field.Value));
                    }
                    else if (type == typeof(DateTime))
                    {
                        view = new DatePicker()
                        {
                        };
                        view.SetBinding(DatePicker.DateProperty, nameof(field.Value));
                    }
                    if (view != null)
                    {
                        view.BindingContext = field;
                    }
                }
            }
            return(view as Element);
        }
Ejemplo n.º 3
0
        public override Element GetEditor(EditableField field, object parent)
        {
            Element view = null;

            if (view == null)
            {
                if (field.PropertyData.Readonly)
                {
                    view = new TextCell()
                    {
                        Text           = ObjectEditor.Translate(field.PropertyData.Title),
                        BindingContext = field,
                        Detail         = field.Value.ToString()
                    };
                    view.SetBinding(TextCell.DetailProperty, nameof(field.Value));
                }
                else
                {
                    var type = field.SourceProperty.PropertyType;
                    if (field.PropertyData.RelationTo != null)
                    {
                        var inst = Activator.CreateInstance(field.PropertyData.RelationTo);
                        if (inst is IEditorRelation rel)
                        {
                            view = new RelationCell(rel)
                            {
                                Text = ObjectEditor.Translate(field.PropertyData.Title)
                            };
                            view.SetBinding(DateCell.ValueProperty, nameof(field.Value));
                        }
                    }
                    else if (type == typeof(string) || type == typeof(int))
                    {
                        view = new EntryCell()
                        {
                            Label = ObjectEditor.Translate(field.PropertyData.Title)
                        };
                        view.SetBinding(EntryCell.TextProperty, nameof(field.Value));
                    }
                    else if (type == typeof(bool))
                    {
                        view = new SwitchCell()
                        {
                            Text = ObjectEditor.Translate(field.PropertyData.Title)
                        };
                        view.SetBinding(SwitchCell.OnProperty, nameof(field.Value));
                    }
                    else if (type == typeof(DateTime))
                    {
                        view = new DateCell()
                        {
                            Text = ObjectEditor.Translate(field.PropertyData.Title)
                        };
                        view.SetBinding(DateCell.ValueProperty, nameof(field.Value));
                    }
                    if (view != null)
                    {
                        view.BindingContext = field;
                    }
                }
            }
            return(view as Element);
        }