Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Problem with MessageBox(es)

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?

like image 717
Spo Avatar asked Nov 14 '22 04:11

Spo


1 Answers

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.

like image 89
BertuPG Avatar answered Dec 06 '22 13:12

BertuPG