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
{
开发者_Go百科 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.
I just tried this on a Windows 7 64-bit multi monitor system in Visual Studio 2010 with .NET 4.0 C#/WPF and it ran fine for me.
The only difference is my MessageBox.Show does not take in the 'this' object.
Are you using System.Windows.MessageBox?
Maybe it just needs a Windows update and/or a reinstall of the .NET framework.
精彩评论