コード例 #1
0
        public object Render(T obj, EditorField <T> editorFieldInfo, Action preview)
        {
            object value = editorFieldInfo.GetValue(obj);

            var options = GetOptions(editorFieldInfo);

            var selectedOption = options.Where(e => Equals(e.Value, value)).Select(e => e.Label).FirstOrDefault();

            _selectBox = new Controls.SelectBox(options.Select(e => e.Label).ToArray())
            {
                SelectedOption = selectedOption
            };

            _selectBox.SelectionChanged += (sender, args) => preview();

            _selectBox.Enabled = editorFieldInfo.Enabled;

            return(_field = new Field(
                       editorFieldInfo.Label,
                       _selectBox,
                       editorFieldInfo.Description,
                       editorFieldInfo.Helper,
                       editorFieldInfo.Required
                       ));
        }
コード例 #2
0
        public void Refresh(QueryBuilder <T> builder)
        {
            Action refresh = null;

            object RenderRule(IQueryRule <T> rule)
            {
                if (rule is GroupRule <T> group)
                {
                    return(group.Render(builder));
                }

                var lstRules = new Controls.SelectBox(builder.Labels.ToArray(), rule.RuleIndex)
                {
                    Width = "15em"
                };

                lstRules.SelectionChanged += (_, __) =>
                {
                    var index = _rules.IndexOf(rule);
                    _rules.Remove(rule);
                    var newRule = builder.Rules[lstRules.SelectedIndex]();
                    newRule.RuleIndex = lstRules.SelectedIndex;
                    _rules.Insert(index, newRule);
                    refresh();
                };

                var chkNegate = new Controls.CheckBox("NOT", false, (chk) =>
                {
                    rule.Negate = chk.Checked;
                });

                var btnDelete = new IconButton(Icons.Delete, (_) =>
                {
                    _rules.Remove(rule);
                    refresh();
                });

                return(Layout.Horizontal(lstRules, chkNegate, rule.Render(builder), btnDelete));
            }

            refresh = () =>
            {
                if (_dc != null)
                {
                    _dc.Content = Layout.Vertical(_rules.Select(RenderRule));
                    _dc.Refresh();
                }
            };

            refresh();
        }