示例#1
0
 public XTab(XTabs parent, string title, RenderFragment renderFragment, string cssClass, bool inactiveRender)
 {
     _parent        = parent;
     Title          = title;
     ChildContent   = renderFragment;
     CssClass       = cssClass;
     InactiveRender = inactiveRender;
 }
        private void RenderPageWithParameters(RenderTreeBuilder builder)
        {
            var pageFragment = RenderNewPage();

            var xTabTitle          = RouteData.PageType.Name;
            var xTabCssClass       = string.Empty;
            var xTabInactiveRender = false;

            var pageAttr = RouteData.PageType.GetCustomAttribute <XTabPageAttribute>();

            if (pageAttr is not null)
            {
                xTabTitle          = pageAttr.Title;
                xTabCssClass       = pageAttr.CssClass;
                xTabInactiveRender = pageAttr.InactiveRender;
            }

            if (_xTabs is null)
            {
                var xTabFragment = new RenderFragment(rBuilder =>
                {
                    rBuilder.OpenComponent(0, typeof(XTab));
                    rBuilder.AddAttribute(1, nameof(XTab.ChildContent), pageFragment);
                    rBuilder.AddAttribute(2, nameof(XTab.Title), xTabTitle);
                    rBuilder.AddAttribute(3, nameof(XTab.CssClass), xTabCssClass);
                    rBuilder.AddAttribute(4, nameof(XTab.InactiveRender), xTabInactiveRender);
                    rBuilder.CloseComponent();
                });

                _xTabsRenderFragment = new RenderFragment(rBuilder =>
                {
                    rBuilder.OpenComponent <XTabs>(0);

                    rBuilder.AddAttribute(1, nameof(XTabs.RenderMode), RenderMode);
                    rBuilder.AddAttribute(2, nameof(XTabs.CloseTabs), CloseTabs);
                    rBuilder.AddAttribute(3, nameof(XTabs.NewTabSetActive), NewTabSetActive);
                    rBuilder.AddAttribute(4, nameof(XTabs.ChildContent), xTabFragment);
                    rBuilder.AddAttribute(5, nameof(XTabs.PreviousStepsContent), PreviousStepsContent);
                    rBuilder.AddAttribute(6, nameof(XTabs.NextStepsContent), NextStepsContent);
                    rBuilder.AddAttribute(7, nameof(XTabs.CssClass), CssClass);
                    rBuilder.AddAttribute(8, nameof(XTabs.OnTabAdded), OnTabAdded);
                    rBuilder.AddAttribute(9, nameof(XTabs.OnActiveTabChanged), OnActiveTabChanged);
                    rBuilder.AddAttribute(10, nameof(XTabs.OnTabRemoved), OnTabRemoved);
                    rBuilder.AddAttribute(11, nameof(XTabs.OnPreviousSteps), OnPreviousSteps);
                    rBuilder.AddAttribute(12, nameof(XTabs.OnNextSteps), OnNextSteps);
                    rBuilder.AddAttribute(13, nameof(XTabs.IsLoading), IsLoading);
                    rBuilder.AddAttribute(14, nameof(XTabs.IsDraggable), IsDraggable);
                    rBuilder.AddAttribute(15, nameof(XTabs.CloseAllTabs), CloseAllTabs);
                    rBuilder.AddAttribute(16, nameof(XTabs.ShowCloseAllTabsButton), ShowCloseAllTabsButton);
                    rBuilder.AddAttribute(17, nameof(XTabs.CloseAllTabsButtonThreshold), CloseAllTabsButtonThreshold);
                    rBuilder.AddAttribute(18, nameof(XTabs.NoTabsNavigatesToHomepage), NoTabsNavigatesToHomepage);

                    rBuilder.AddComponentReferenceCapture(100, compRef => _xTabs = (XTabs)compRef);
                    rBuilder.CloseComponent();
                });
            }
            else
            {
                var xtab = new XTab(_xTabs, xTabTitle, pageFragment, xTabCssClass, xTabInactiveRender);
                _xTabs.AddPageAsync(xtab).Wait();
            }

            builder.OpenElement(0, "XTabs");
            builder.AddContent(1, _xTabsRenderFragment);
            builder.CloseElement();
        }