I found a problem with Show.MessageBox ().
In my application, I call Show.Dialog () in several places to display the default child windows.
Then, if you use Show.MessageBox () in a new child window, a message box appears centered above the main application window. You can place a breakpoint, and the owner of the message box is also the main window.
To fix this, I made a hack with IQuestionDialog:
[Singleton(typeof(IQuestionDialog))]
public class QuestionDialogViewModel : Caliburn.ShellFramework.Questions.QuestionDialogViewModel
{
public override void AttachView(object view, object context)
{
Window window = view as Window;
if (window != null)
{
Window owner = GetTopWindow();
if (owner != null)
{
window.Owner = owner;
}
}
base.AttachView(view, context);
}
private Window GetTopWindow()
{
return Application.Current.Windows
.Cast<Window>()
.Reverse()
.Skip(1)
.FirstOrDefault();
}
}
This will not work for all possible cases, but it works for my application.
Any cleaner way to fix this?
source
share