I am experiencing strange behavior using MessageBox(es) in a C#/WPF program.
Create a basic WPF application put some labels on it and a button.
Here is the code of the button click
private void button1_Click(object sender, RoutedEventArgs e)
{
MessageBoxResult result;
do
{
result = MessageBox.Show(this, "Please Click here under", "TestBugMessageBox", MessageBoxButton.OKCancel, MessageBoxImage.Information, MessageBoxResult.None);
if (result.Equals(MessageBoxResult.OK))
{
result = MessageBox.Show(this, "Is it the first time you see it ?", "TestBugMessageBox", MessageBoxButton.YesNo, MessageBoxImage.Question, MessageBoxResult.None);
}
} while (result.Equals(MessageBoxResult.Yes));
}
Then Place the windows on the center of the screen ( in order for the MessageBox to cover some labels )
Click yes three times, and no the last time and you will see the problem (I hope):
The message box stays shown on the app.
Could you let me know what's wrong with it?
Are you debugging and staying on a breakpoint in the do..while loop? If answer is "yes", you have to remove breakpoints: wpf can't redraw the surface of your window if you lock a cycle on main thread.
EDIT: Even debugging and breakpointing the do..while I wasn't able to reproduce described behaviour. The issue I talked about is only when stopping the UI thread (eg. when overriding Measure || Arrange methods and debugging them), not the main thread. Sorry.
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