public void Render(RenderInfo info) { if (String.IsNullOrEmpty(info.FileName)) { throw new XamlException("No source for render"); } IProfileRequest request = _profile.CurrentRequest; String fileName = String.Empty; UIElementBase uiElem = null; using (request.Start(ProfileAction.Render, $"load: {info.FileTitle}")) { try { // XamlServices.Load sets IUriContext if (!String.IsNullOrEmpty(info.FileName)) { using (var fileStream = _host.ApplicationReader.FileStreamFullPathRO(info.FileName)) { RootFileName = info.FileName; ApplicationReader = _host.ApplicationReader; uiElem = XamlServices.Load(fileStream) as UIElementBase; } } else if (!String.IsNullOrEmpty(info.Text)) { uiElem = XamlServices.Parse(info.Text) as UIElementBase; } else { throw new XamlException("Xaml. There must be either a 'FileName' or a 'Text' property"); } if (uiElem == null) { throw new XamlException("Xaml. Root is not 'UIElement'"); } var stylesPath = _host.ApplicationReader.MakeFullPath(String.Empty, "styles.xaml"); if (_host.ApplicationReader.FileExists(stylesPath)) { using (var stylesStream = _host.ApplicationReader.FileStreamFullPathRO(stylesPath)) { if (stylesStream != null) { if (!(XamlServices.Load(stylesStream) is Styles styles)) { throw new XamlException("Xaml. Styles is not 'Styles'"); } if (uiElem is RootContainer root) { root.Styles = styles; root?.OnSetStyles(); } } } } } finally { RootFileName = null; ApplicationReader = null; } } using (request.Start(ProfileAction.Render, $"render: {info.FileTitle}")) { RenderContext ctx = new RenderContext(uiElem, info) { RootId = info.RootId, Path = info.Path }; if (info.SecondPhase) { if (!(uiElem is ISupportTwoPhaseRendering twoPhaseRender)) { throw new XamlException("The two-phase rendering is not available"); } twoPhaseRender.RenderSecondPhase(ctx); } else { uiElem.RenderElement(ctx); } Grid.ClearAttached(); Splitter.ClearAttached(); FullHeightPanel.ClearAttached(); Toolbar.ClearAttached(); } if (uiElem is IDisposable disp) { disp.Dispose(); } }
internal override void RenderElement(RenderContext context, Action <TagBuilder> onRender = null) { if (SkipRender(context)) { return; } TagBuilder page = null; Boolean isGridPage = (Toolbar != null) || (Taskpad != null) || (Pager != null); // render page OR colleciton view void addGridAction(TagBuilder tag) { if (!isGridPage) { return; } tag.AddCssClass("page-grid"); if (Taskpad != null) { if (Taskpad is Taskpad tp && tp.Width != null) { tag.MergeStyle("grid-template-columns", $"1fr {tp.Width.Value}"); } } } if (CollectionView != null) { CollectionView.RenderStart(context, (tag) => { tag.AddCssClass("page").AddCssClass("absolute"); addGridAction(tag); AddAttributes(tag); tag.MergeAttribute("id", context.RootId); }); } else { page = new TagBuilder("div", "page absolute"); page.MergeAttribute("id", context.RootId); addGridAction(page); AddAttributes(page); page.RenderStart(context); } RenderTitle(context); if (isGridPage) { Toolbar?.RenderElement(context, (tag) => tag.AddCssClass("page-toolbar")); Taskpad?.RenderElement(context, (tag) => tag.AddCssClass("page-taskpad")); Pager?.RenderElement(context, (tag) => tag.AddCssClass("page-pager")); var content = new TagBuilder("div", "page-content").RenderStart(context); RenderChildren(context); content.RenderEnd(context); } else { RenderChildren(context); } var outer = new TagBuilder("div", "page-canvas-outer").RenderStart(context); new TagBuilder("div", "page-canvas").MergeAttribute("id", "page-canvas").Render(context); outer.RenderEnd(context); if (CollectionView != null) { CollectionView.RenderEnd(context); } else { if (page == null) { throw new InvalidProgramException(); } page.RenderEnd(context); } }