Using RenderFragment parameters
A RenderFragment
parameter is a segment of UI content. It is used to communicate UI content from the parent to the child. The UI content can include plain text, HTML markup, Razor markup, or another component.
The following code is for the Alert
component. The UI content of the Alert
component is displayed when the value of its Show
property is true:
Alert.razor
@if (Show)
{
<div>
<div>
<div>
@ChildContent
</div>
<div>
<button @onclick="OnOk">
OK
</button>
</div>
</div>
</div>
}
@code {
[Parameter] public bool Show { get; set; }
[Parameter] public EventCallback OnOk { get; set; }
[Parameter] public RenderFragment ChildContent { get; set;
}
The preceding code, for the Alert
component, includes three different types of parameters: simple...