You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've uploaded a sample project illustrating the issue.
When trying to get a WPF window to open a view using DialogHost on initial startup/show, I noticed that the DialogHost.Show method throws an exception even though the DialogHost instance IsLoaded property was true. I am thinking the DialogHost is loaded but not yet registered in the LoadedInstances HashSet by the time the Window.IsLoaded event triggers.
Looks like IsLoaded property is coming from FrameworkElement, so my guess here is that it's not the correct value to identify whether or not the DialogHost is fully initialized. I am not sure of the best way to solve this problem.
FYI: As far as I can tell the problem is that the Show method is called before the Loaded event of the DialogHost is raised. Therefore the dialoghost instance has not yet been added to the LoadedInstances hashset.
Executing the logic in the Onloaded method when the Initialized event is raised fixes this problem. I am however not confident that this is a suitable fix, because the DialogHost is quite a large class and it could possibly break something else.
That is covered in "Scenario 3" in the sample project I provided. It works only if the DialogHost was not already loaded/initialized prior to the window constructor call (which I admit won't be a problem for most users).
Activity
corvinsz commentedon Mar 11, 2025
FYI: As far as I can tell the problem is that the
Showmethod is called before theLoadedevent of theDialogHostis raised. Therefore the dialoghost instance has not yet been added to theLoadedInstanceshashset.Executing the logic in the
Onloadedmethod when theInitializedevent is raised fixes this problem. I am however not confident that this is a suitable fix, because the DialogHost is quite a large class and it could possibly break something else.MaterialDesignInXamlToolkit/src/MaterialDesignThemes.Wpf/DialogHost.cs
Line 288 in ae59e31
public DialogHost() { - Loaded += OnLoaded; + Initialized += OnLoaded; Unloaded += OnUnloaded; CommandBindings.Add(new CommandBinding(CloseDialogCommand, CloseDialogHandler, CloseDialogCanExecute)); CommandBindings.Add(new CommandBinding(OpenDialogCommand, OpenDialogHandler)); }Edit: @jbooth88 if applicable and you need a quick & dirty fix you can just listen for the
Loadedevent on theDialogHostlike so:jbooth88 commentedon Mar 11, 2025
That is covered in "Scenario 3" in the sample project I provided. It works only if the DialogHost was not already loaded/initialized prior to the window constructor call (which I admit won't be a problem for most users).
AmeerMansour commentedon Mar 29, 2025
@corvinsz
can you please help me and check my issue as i am not expert in material design toolkit structure ?
#3824