forked from chocolatey/ChocolateyGUI
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(chocolatey#904) Wrap MessageBoxes with a hidden window
There appears to be a "feature" in WPF that prevents MessageBoxes from displaying when there are no active windows. Many of our MessageBoxes are to report errors, and many of them occur during startup. This results in them not displaying as we haven't created any windows. This works around that by creating a hidden window and closing it after the MessageBox has been displayed.
- Loading branch information
Showing
7 changed files
with
78 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
Source/ChocolateyGui.Common.Windows/Utilities/ChocolateyMessageBox.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
// <copyright company="Chocolatey" file="ChocolateyMessageBox.cs"> | ||
// Copyright 2017 - Present Chocolatey Software, LLC | ||
// Copyright 2014 - 2017 Rob Reynolds, the maintainers of Chocolatey, and RealDimensions Software, LLC | ||
// </copyright> | ||
// -------------------------------------------------------------------------------------------------------------------- | ||
|
||
namespace ChocolateyGui.Common.Windows.Utilities | ||
{ | ||
using System.Windows; | ||
|
||
public static class ChocolateyMessageBox | ||
{ | ||
public static MessageBoxResult Show(string messageBoxText) | ||
{ | ||
var dummyWindow = DummyWindow(); | ||
dummyWindow.Show(); | ||
var result = MessageBox.Show(messageBoxText); | ||
dummyWindow.Close(); | ||
return result; | ||
} | ||
|
||
public static MessageBoxResult Show(string messageBoxText, string caption) | ||
{ | ||
var dummyWindow = DummyWindow(); | ||
dummyWindow.Show(); | ||
var result = MessageBox.Show(messageBoxText, caption); | ||
dummyWindow.Close(); | ||
return result; | ||
} | ||
|
||
public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button) | ||
{ | ||
var dummyWindow = DummyWindow(); | ||
dummyWindow.Show(); | ||
var result = MessageBox.Show(messageBoxText, caption, button); | ||
dummyWindow.Close(); | ||
return result; | ||
} | ||
|
||
public static MessageBoxResult Show(string messageBoxText, string caption, MessageBoxButton button, MessageBoxImage icon, MessageBoxResult defaultResult, MessageBoxOptions options) | ||
{ | ||
var dummyWindow = DummyWindow(); | ||
dummyWindow.Show(); | ||
var result = MessageBox.Show(messageBoxText, caption, button, icon, defaultResult, options); | ||
dummyWindow.Show(); | ||
return result; | ||
} | ||
|
||
private static Window DummyWindow() | ||
{ | ||
return new Window | ||
{ | ||
AllowsTransparency = true, | ||
Background = System.Windows.Media.Brushes.Transparent, | ||
WindowStyle = WindowStyle.None, | ||
Top = 0, | ||
Left = 0, | ||
Width = 1, | ||
Height = 1, | ||
ShowInTaskbar = false | ||
}; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters