I want to use following Renderfragment for two different Modals. I want to pass two parameters: the heading and a function, when the BackIcon is clicked. How can I pass also the function OnVisiblityChanged?
@{
RenderFragment <string> BackIconTitle = heading =>@<Template>
<div class="title-with-icon">
<div class="back-icon" @onclick="() =>OnVisiblityChanged()">
<ArrowLeftIcon Height="1.5rem" Width="1.5rem"/>
</div>
<div class="back-icon-title">@heading</div>
</div>
</Template>;
}
<Modal
Visible="@isVisible"
TitleTemplate="@BackIconTitle(Loc["Some Heading"])"
Footer="@BackIconFooter"
DestroyOnClose="true"
OnCancel="@OnVisiblityChanged"
Width="@("1000px")">
<DeliveryTimeContent IsModalView="true"/>
</Modal>
private void OnVisiblityChanged()
{
if (isVisible)
{
isVisible= false;
}
else
{
isVisble= true;
}
StateHasChanged();
}
Thank you in advance!
I've taken your code and created a very simple page and component to demo what I believe you are trying to do.
Component.razor
A Modal is just another component.
And then the main page.
You pass the method as a Func. You need to be precise with your definition. My function pattern conforms to the standard
@onclickevent pattern:Task EventMethod(MouseEventArgs e)