Closed hengway closed 4 days ago
I found an alternative solution to the issue by placing the code below in the dialog's ViewModel constructor.
foreach (Window window in Application.Current.Windows)
{
if (window.GetType().Name == "MainWindow" || window.GetType().Name == "DialogWindow")
{
window.Activate();
}
}
By refocus all the window in the window stack seem work.
You did not provide a sample that reproduces the issue. However, I'm not sure this is a bug. This appears to be standard WPF behavior. The Prism WPF dialog service simply wraps showing a window from a VM and relies on WPF's default Window behaviors. Showing a dialog/window without user interaction and while the application does not have focus seems like a very strange scenario for me.
@brianlagunas Thank you for your response. While setting up the sample project, I finally identified the root cause—it was due to the window style applied to the dialog.
<prism:Dialog.WindowStyle>
<Style TargetType="{x:Type Window}">
<Setter Property="WindowStyle" Value="ToolWindow" /> <--- the issue happen after apply this
</Style>
</prism:Dialog.WindowStyle>
Below is the sample code:
And I had record video on the issue reproduce step https://github.com/user-attachments/assets/9833300d-4dbb-406d-93eb-9d7e1759aa2e
I applied the style to customize the dialog's appearance. However, after commenting it out, the issue seems gone.
I believe the bug may originate from the window behavior. This issue occurs in my payment processing application when a user switches to another application during a transaction, and the success or error dialog fails to appear at the end.
Anyway thank you for the framework.
Glad you figured it out. Thanks for sharing your solution for others.
Description
I'm using the Prism Library to manage dialogs with IDialogService. The issue I encountered is that when the main application window becomes inactive (deactivated) and a dialog is opened via ShowDialog(), the dialog is created but does not become visible or active. However, I can confirm that the dialog instance is created correctly, as its logic runs in the background, but the UI doesn’t show even the user manually focuses on the parent window at the later on.
Steps to Reproduce
Platform with bug
WPF
Affected platforms
Windows
Did you find any workaround?
I did found a solution which is when invoke the dialog invoke
Application.Current.MainWindow.Activate();
but this create an issue, which if I open a "Dialog B" from a "Dialog A", when the "Dialog B" close, the focus will go to the MainWindow but not the "Dialog A"Relevant log output
No response