Dialog with MVVM

I have a Blazor-MAUI Application and want use the MVVM-Pattern.

In my ViewModel-Class I want to write the code for open a Dialog with a small message (like "Server is not available" or "Your password is wrong").

How can i find a sample for that , why the samples on the webpage are only show the usage on a razor-page

1 Like

There are examples that display simple messages. Check the display inline content one.

@inject DialogService DialogService

<div class="rz-p-12 rz-text-align-center">
    <RadzenButton Text="Dialog with inline Blazor content" ButtonStyle="ButtonStyle.Secondary" Click=@ShowInlineDialog />
</div>

@code {
    int orderID = 10248;

    async Task ShowInlineDialog()
    {
        var result = await DialogService.OpenAsync("Simple Dialog", ds =>
        @<RadzenStack Gap="1.5rem">
            <p>Confirm Order ID <b>@orderID</b>?</p>
            <RadzenStack Orientation="Orientation.Horizontal" Gap="0.5rem" AlignItems="AlignItems.Center" JustifyContent="JustifyContent.SpaceBetween">
                <RadzenStack Orientation="Orientation.Horizontal">
                    <RadzenButton Text="Ok" Click="() => ds.Close(true)" Style="width: 80px;" />
                    <RadzenButton Text="Cancel" Click="() => ds.Close(false)" ButtonStyle="ButtonStyle.Light" />
                </RadzenStack>
                <RadzenButton Text="Refresh" Click="(() => { orderID = 10249; ds.Refresh(); })" ButtonStyle="ButtonStyle.Light" />
            </RadzenStack>
        </RadzenStack>);
    }
}
1 Like

Thank you for this example.

But my problem is, that the "View" is in one DLL and the "ModelView-Class" is in a different Class. The View has a link to the ModelView-Dll

How is possible to open the Dialog from the linked Class-DLL?

1 Like

I am not familiar with this pattern. You can probably use RenderTreeBuilder or any other way to create a RenderFragment. Check online for tips how to use RenderFragments with your MVVM framework.

Hi, maybe you must to read the next article. Currently I’m working with WPF and the MVVM pattern and let me say that all in the article is clear and easy to understand. Fortunately Blazor uses dependency injection and with this the MVVM pattern can be used.

Read more here

Regards