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
Here's why: In a recent project, I encountered an issue where after using ShowMessageBox, the popup window, which I will call Window-A, quickly disappeared, and my entire UI became unresponsive. After some investigation, I found the root cause. The default implementation of IWindowManager, WindowManager, has a call to this.ShowDialog(vm) in the ShowMessageBox function. Since ShowDialog doesn't specify an owner window, Stylet defaults to using the activated window as its owner. In my project, a small notification popup window, which I will cal Window-B, appears before calling ShowMessageBox, which automatically disappears after 2 seconds. The ShowMessageBox popup Window-A then incorrectly takes this notification popup Window-B as its owner. When the notification popup Window-B disappears, the ShowMessageBox popup Window-A also disappears due to losing its owner. Since Window-A is a modal window, the entire UI appears to be frozen.
I propose changing the ShowMessageBox function signature to:
public MessageBoxResult ShowMessageBox(stringmessageBoxText,stringcaption="",MessageBoxButtonbuttons= MessageBoxButton.OK,MessageBoxImageicon= MessageBoxImage.None,MessageBoxResultdefaultResult= MessageBoxResult.None,MessageBoxResultcancelResult= MessageBoxResult.None,IDictionary<MessageBoxResult,string>buttonLabels=null,FlowDirection?flowDirection=null,TextAlignment?textAlignment=null,IViewAwareviewModel=null)
Adding an IViewAware parameter last allows for more flexible specification of the owner window for ShowDialog to call ShowDialog(vm, viewModel), preventing the above issue. Since this parameter defaults to null, it will also be compatible with existing code.
Here's why: In a recent project, I encountered an issue where after using
ShowMessageBox
, the popup window, which I will call Window-A, quickly disappeared, and my entire UI became unresponsive. After some investigation, I found the root cause. The default implementation ofIWindowManager
,WindowManager
, has a call tothis.ShowDialog(vm)
in theShowMessageBox
function. SinceShowDialog
doesn't specify an owner window, Stylet defaults to using the activated window as its owner. In my project, a small notification popup window, which I will cal Window-B, appears before calling ShowMessageBox, which automatically disappears after 2 seconds. The ShowMessageBox popup Window-A then incorrectly takes this notification popup Window-B as its owner. When the notification popup Window-B disappears, the ShowMessageBox popup Window-A also disappears due to losing its owner. Since Window-A is a modal window, the entire UI appears to be frozen.I propose changing the ShowMessageBox function signature to:
Adding an
IViewAware
parameter last allows for more flexible specification of the owner window forShowDialog
to callShowDialog(vm, viewModel)
, preventing the above issue. Since this parameter defaults to null, it will also be compatible with existing code.Originally posted by @TreatTrick in #391
The text was updated successfully, but these errors were encountered: