Что я хочу сделать
MyGrid.razor
@page "/mygrid"
@inherits GridPage @*or "layout" or whatever works*@
@code {
protected overrides string Title => "My Grid"
}
< /code>
GridPage.cs
@Title
@ChildContent
@code {
[Parameter] public string Title { get; set; }
[Parameter] public RenderFragment ChildContent { get; set; }
}
< /code>
Solutions I have tried
- Layout - GridLayout
@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
- Template
< /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.
- Abstract base class
{
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);).
желаемый результат
Скажем, у вас есть две сетки .. студенты Сетка и классы Grid. Я бы хотел другую сетку (и заголовок) для каждого из них. Я хочу настроить заголовок и столбцы для каждого в основном. У них будет общая разметка макета (как я называю Gridpage ), но Mygrid (либо студенты , либо классы ) были бы разными.
Students.razor
@page "/students"
@inherits GridPage
@code {
protected overrides string Title => "Students"
}
< /code>
Classes.razor
@page "/classes"
@inherits GridPage
@code {
protected overrides string Title => "Classes"
}
< /code>
They would both output
Title_here
Grid_markup_here
Подробнее здесь: https://stackoverflow.com/questions/693 ... -component
Мобильная версия