示例#1
0
        public override void RenderElement(RenderContext context, Action <TagBuilder> onRender = null)
        {
            if (CheckDisabledModel(context))
            {
                return;
            }
            var input = new TagBuilder("a2-selector", null, IsInGrid);

            onRender?.Invoke(input);
            if (!String.IsNullOrEmpty(Delegate))
            {
                input.MergeAttribute(":fetch", $"$delegate('{Delegate}')");
            }
            if (!String.IsNullOrEmpty(SetDelegate))
            {
                input.MergeAttribute(":hitfunc", $"$delegate('{SetDelegate}')");
            }
            input.MergeAttribute("display", DisplayProperty);
            if (PanelPlacement != DropDownPlacement.BottomLeft)
            {
                input.MergeAttribute("placement", PanelPlacement.ToString().ToKebabCase());
            }
            if (Style != SelectorStyle.Default)
            {
                input.MergeAttribute("mode", Style.ToString().ToKebabCase());
            }
            if (Size != ControlSize.Default)
            {
                input.AddCssClass($"sel-{Size.ToString().ToLowerInvariant()}");
            }
            if (ListSize != null)
            {
                if (!ListSize.Width.IsEmpty)
                {
                    input.MergeAttribute("list-width", ListSize.Width.ToString());
                }
                if (!ListSize.Height.IsEmpty)
                {
                    input.MergeAttribute("list-height", ListSize.Height.ToString());
                }
            }
            if (ShowCaret.HasValue && ShowCaret.Value)
            {
                input.MergeAttribute(":caret", "true");
            }
            if (ShowClear)
            {
                input.MergeAttribute(":has-clear", "true");
            }

            var isBind = GetBinding(nameof(ItemsSource));

            if (isBind != null)
            {
                input.MergeAttribute(":items-source", isBind.GetPath(context));
            }

            MergeAttributes(input, context);
            MergeDisabled(input, context);
            MergeAlign(input, context, Align);
            MergeBindingAttributeString(input, context, "placeholder", nameof(Placeholder), Placeholder);
            MergeValue(input, context);
            MergeCustomValueItemProp(input, context, nameof(TextValue), "text");
            MergeCreateNew(input, context);

            input.RenderStart(context);
            RenderAddOns(context);
            //RenderNewPane(context);
            RenderPaneTemplate(context);
            input.RenderEnd(context);
        }
示例#2
0
        public override void RenderElement(RenderContext context, Action <TagBuilder> onRender = null)
        {
            if (SkipRender(context))
            {
                return;
            }
            var dataGrid = new TagBuilder("data-grid", null, IsInGrid);

            onRender?.Invoke(dataGrid);
            MergeBindingAttributeBool(dataGrid, context, ":compact", nameof(Compact), Compact);
            MergeAttributes(dataGrid, context, MergeAttrMode.Margin | MergeAttrMode.Visibility);
            dataGrid.MergeAttribute("key", Guid.NewGuid().ToString());             // disable vue reusing
            if (Height != null)
            {
                dataGrid.MergeStyle("height", Height.Value);
            }
            if (FixedHeader)
            {
                dataGrid.MergeAttribute(":fixed-header", "true");
            }
            if (HeadersVisibility == HeadersVisibility.None)
            {
                dataGrid.MergeAttribute(":hide-header", "true");
            }
            if (Style != DataGridStyle.Default)
            {
                dataGrid.AddCssClass($"data-grid-{Style.ToString().ToKebabCase()}");
            }
            if (RowDetails != null)
            {
                dataGrid.MergeAttribute(":row-details", "true");
                dataGrid.MergeAttribute("row-details-activate", RowDetails.Activate.ToString().ToLowerInvariant());
                var vBind = RowDetails.GetBinding("Visible");
                if (vBind != null)
                {
                    dataGrid.MergeAttribute("row-details-visible", vBind.Path /*!without context!*/);
                }
            }
            var isb = GetBinding(nameof(ItemsSource));

            if (isb != null)
            {
                dataGrid.MergeAttribute(":items-source", isb.GetPath(context));
            }
            MergeBoolAttribute(dataGrid, context, nameof(Hover), Hover);
            MergeBoolAttribute(dataGrid, context, nameof(Striped), Striped);
            MergeBoolAttribute(dataGrid, context, nameof(Border), Border);
            MergeBoolAttribute(dataGrid, context, nameof(Sort), Sort);
            dataGrid.MergeAttribute(":route-query", "$query");             // always!
            if (!String.IsNullOrEmpty(EmptyPanelDelegate))
            {
                dataGrid.MergeAttribute(":empty-panel-callback", $"$delegate('{EmptyPanelDelegate}')");
            }


            var dblClickBind = GetBindingCommand(nameof(DoubleClick));

            if (dblClickBind != null)
            {
                // Function!
                dataGrid.MergeAttribute(":doubleclick", "() => " + dblClickBind.GetCommand(context));
            }

            if (MarkerStyle != RowMarkerStyle.None)
            {
                dataGrid.MergeAttribute("mark-style", MarkerStyle.ToString().ToKebabCase());
            }

            var mbind = GetBinding(nameof(Mark));

            if (mbind != null)
            {
                dataGrid.MergeAttribute("mark", mbind.Path);                 // without context!!!
            }
            else if (Mark != MarkStyle.Default)
            {
                throw new XamlException("The Mark property must be a binding");
            }
            var rbbind = GetBinding(nameof(RowBold));

            if (rbbind != null)
            {
                dataGrid.MergeAttribute("row-bold", rbbind.GetPath(context));
            }
            else if (RowBold != null)
            {
                throw new XamlException("The RowBold property must be a binding");
            }

            // TODO: binding for GridLines ???
            if (GridLines != GridLinesVisibility.None)
            {
                dataGrid.MergeAttribute("grid", GridLines.ToString());
            }

            var groupByBind = GetBinding(nameof(GroupBy));

            if (groupByBind != null)
            {
                dataGrid.MergeAttribute(":group-by", groupByBind.GetPath(context));
            }
            else if (_groupBy != null)
            {
                dataGrid.MergeAttribute(":group-by", _groupBy.GetJsValue(context));
            }

            dataGrid.RenderStart(context);
            Int32 colIndex = 0;

            foreach (var col in Columns)
            {
                col.RenderColumn(context, colIndex);
                colIndex++;
            }
            RenderRowDetails(context);
            RenderEmptyPanel(context);
            RenderFooter(context);
            dataGrid.RenderEnd(context);
        }