I have a WPF application where the window gets small and moved to the side if it gets deactivated. But I dont want this feature to happen if there is a messagebox open on the window. Is there a way we can check if there is any dialog box open in C# code?
Wrap the call to your MessageBox in a static class/method. If this is called set a flag that your MessageBox is open.
Something like this:
public class MessageBoxWrapper
{
public static bool IsOpen {get;set;}
// give all arguments you want to have for your MSGBox
public static void Show(string messageBoxText, string caption)
{
IsOpen = true;
MessageBox.Show(messageBoxText, caption);
IsOpen = false;
}
}
Usage:
MessageBoxWrapper.Show("TEST","TEST");
MessageBoxWrapper.IsOpen
But you have to make sure to always use the Wrapper to call a MessageBox
Set a flag somewhere when you open a MessageBox. Unset it when the MessageBox is closed.
Check the flag when you handling the deactivation.
If there's a possibility of more than one MessageBox being open at a time then you'll need to give that some thought, otherwise one closing will make it look like there are none open.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With