|
@using Syncfusion.Blazor.Popups
<SfDialog @ref="DialogObj" @bind-Visible="@Visible" IsModal="@IsModal" Width="250px">
<DialogTemplates>
<Header> @Header </Header>
<Content> @((MarkupString)Content) </Content>
</DialogTemplates>
<DialogButtons>
<DialogButton Content="OK" IsPrimary="true" OnClick="@OnOkClick" />
<DialogButton Content="Cancel" OnClick="@OnCancelClick" />
</DialogButtons>
</SfDialog>
@code {
SfDialog DialogObj;
[Parameter]
public string Header { get; set; } = "";
[Parameter]
public string Content { get; set; } = "";
[Parameter]
public bool Visible { get; set; } = false;
[Parameter]
public bool IsModal { get; set; } = true;
public void Show(string title, string message)
{
this.Header = title;
this.Content = message;
Visible = true;
this.StateHasChanged();
}
private void OnOkClick()
{
Visible = false;
}
private void OnCancelClick()
{
Visible = false;
}
}
|
|
<button class="e-btn" @onclick="ShowDialog">Show Confirm Dialog</button>
<CascadingValue Value="@this">
<ReusableDialog @ref="Dialog" Visible=@Visibility IsModal="@IsModal"></ReusableDialog>
</CascadingValue>
@code {
[CascadingParameter]
ReusableDialog Dialog { get; set; }
public bool Visibility { get; set; } = false;
public bool IsModal { get; set; } = true;
private void ShowDialog()
{
this.Dialog.Show("rewr", "test");
}
}
|
Hi,
I am also interested in this concept. From the sample given you expose Content as a string but could you elaborate on how to set the Content to be another Blazor Component please?
Hi Joshua,
Thank you for reaching out to us with your question about cascading parameters in the attached sample. We understand that you're looking for assistance in passing data across a component hierarchy.
To achieve this in the provided sample, you can utilize the "Show" method within the "ReusableDialog.razor" component. By calling this method and passing the appropriate arguments for the title and message, you can set the dialog content and make it visible. Here's an example of how you can use the "Show" method:
ReusableDialog.razor
|
public void Show(string title, string message) { this.Header = title; this.Content = message; // Here, set the dialog content Visible = true; this.StateHasChanged(); } |
In addition, please make sure to establish a cascading parameter between the current component and the "ReusableDialog" component by using the [CascadingParameter] attribute. With the cascading parameter set, you can call the "Show" method to pass the dialog header and content as arguments. Here's an example:
Index.razor
|
@code { [CascadingParameter] ReusableDialog Dialog { get; set; }
private void ShowDialog() { this.Dialog.Show("Header", "Content"); // Here, pass the dialog header and content as argument } } |
Please refer the below page for more reference.
Regards,
Buvana S
Hi
Question number 1
Can you modify the above sample using the Mvvm pattern, preferably using the CommunityToolkit.Mvvm library.
Question number 2
Is it possible to obtain a feedback parameter from such an open dialogue (according to the assumptions from question no. 1). Let's say the user has to enter some text. I would like to send the entered text back to the ViewModel.
Question number 3
Is it possible to open the dialogue from ViewMdel?
Is such a solution possible?
If so, can I have a code sample please?
Regards
Bogdan
You can refer to the following Syncfusion blogs for more information regarding your requirements: