canton7 / canton7/Stylet

Add IViewAware to IWindowManager.ShowMessageBox

Open
#393 0 comments 0 reactions 0 assignees View on GitHub
fix-scheduled
Dominant language
C#
Stars
1.1k
Forks
155
PR merge metrics
No merged PRs in 30d

Description

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:
``` C#
public MessageBoxResult ShowMessageBox(string messageBoxText, string caption = "",
MessageBoxButton buttons = MessageBoxButton.OK,
MessageBoxImage icon = MessageBoxImage.None,
MessageBoxResult defaultResult = MessageBoxResult.None,
MessageBoxResult cancelResult = MessageBoxResult.None,
IDictionary buttonLabels = null,
FlowDirection? flowDirection = null,
TextAlignment? textAlignment = null,
IViewAware viewModel = 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.

_Originally posted by @TreatTrick in https://github.com/canton7/Stylet/discussions/391_

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.