Was ich tun möchte
Code: Select all
MyGrid.razor
Code: Select all
@page "/mygrid"
@inherits GridPage @*or "layout" or whatever works*@
@code {
protected overrides string Title => "My Grid"
}
< /code>
GridPage.cs
Code: Select all
@Title
@ChildContent
@code {
[Parameter] public string Title { get; set; }
[Parameter] public RenderFragment ChildContent { get; set; }
}
< /code>
[b]Solutions I have tried[/b]
[list]
[*]Layout - GridLayout
Code: Select all
@Title
@Body
@code {
[CascadingParameter]
[Parameter] public string Title { get; set; }
}
< /code>
Issue is that you have to remember this param is available and it is not required to implement
[list]
[*]Template
[/list]
< /code>
Issue here is that I would have to wrap my component with the template (not that big of deal, but would rather inherit) and I still don't know which params are required to implement.
[list]
[*]Abstract base class
[/list]
public abstract class GridPage : ComponentBase
{
protected abstract string Title { get; }
protected override void BuildRenderTree(RenderTreeBuilder builder)
{
builder.OpenRegion(0);
builder.OpenElement(1, "header");
builder.AddContent(2, Title);
builder.CloseElement();
builder.CloseRegion();
builder.OpenElement(3, "div")
builder.OpenRegion(10);
this.BuildRenderTree(builder);
builder.CloseRegion();
builder.Closelement()
}
}
< /code>
Issue is this one doesn't seem to work. I actually thought it would cause it would just take in the component and continue the base render (this.BuildRenderTree(builder);
Code: Select all
Students.razor
Code: Select all
@page "/students"
@inherits GridPage
@code {
protected overrides string Title => "Students"
}
< /code>
Classes.razor
Code: Select all
@page "/classes"
@inherits GridPage
@code {
protected overrides string Title => "Classes"
}
< /code>
They would both output
Title_here
Grid_markup_here