-
|
I’m working with MaterialDesignInXaml – DialogHost in a WPF application and I have a question about the behavior (and naming) of the Opened event. What I’m trying to achieve I want the dialog to:
Current behavior The Opened handler is executed before the dialog is visually rendered. This makes it impossible to reliably show a loading state at dialog startup. await DialogHost.Show(dialogView, "RootDialog", SalesRecordDialogOpened);
private async void SalesRecordDialogOpened(object sender, DialogOpenedEventArgs eventArgs)
{
var view = (SalesRecordDialog)eventArgs.Session.Content!;
var viewModel = (SalesRecordDialogViewModel)view.DataContext;
await viewModel.LoadSaleRecords();
}What I tried
Unfortunately, even with Loaded, the dialog still doesn’t reliably render before the loading starts. My questions -Is this behavior by design? -Would the name Opened be more accurate as Opening, since it fires before the dialog is actually rendered? -Is there a recommended pattern to ensure: The dialog is fully visible I’m open to any suggestions to deal with this |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 3 replies
-
|
@BrensNina I can't reproduce the problem you are describing. Could this be a problem with how you are consuming this library?
https://github.com/corvinsz/LoadDataOnDialogHostOpeningExample
Alternative approachWhile your approach works, you are forced to define an async void method, which - as you might know - is not best practice.
<i:Interaction.Triggers>
<i:EventTrigger EventName="Loaded">
<i:InvokeCommandAction Command="{Binding LoadSaleRecordsCommand}" />
</i:EventTrigger>
</i:Interaction.Triggers>
|
Beta Was this translation helpful? Give feedback.
@BrensNina I can't reproduce the problem you are describing. Could this be a problem with how you are consuming this library?
I have created a repo which showcases your needs:
https://github.com/user-attachments/assets/9cbbea1e-b20a-4a7b-97af-b2ce7f8b5f20
https://github.com/corvinsz/LoadDataOnDialogHostOpeningExample
LoadDataOnDialogHostOpeningExampleis your approach.LoadDataOnDialogHostOpeningExample2is my alternative approach described below.Alternative approach
While your approach works, you are forced to define an async void method, which - as you might know - is not best practice.
I commonly just bind the loaded event …