MessageBox的问题

时间:2011-01-04 04:31:24

标签: c# wpf refresh messagebox

我在C#/ WPF程序中使用MessageBox遇到奇怪的行为。

创建一个基本的WPF应用程序,在其上放置一些标签和一个按钮。

以下是按钮点击的代码

    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));
    }

然后将窗口放在屏幕中央(为了让MessageBox覆盖一些标签)

单击是三次,最后一次没有,你会看到问题(我希望):

消息框保持显示在应用程序上。

你能告诉我它有什么问题吗?

2 个答案:

答案 0 :(得分:1)

你是否在do..while循环中调试并保持断点? 如果回答为“是”,则必须删除断点:如果在主线程上锁定循环,则wpf无法重绘窗口的表面。

编辑: 甚至调试和破坏了do..while虽然我无法重现描述的行为。 我谈到的问题仅在停止UI线程时(例如,当重写Measure || Arrange方法并调试它们时),而不是主线程。遗憾。

答案 1 :(得分:0)

我刚刚在带有.NET 4.0 C#/ WPF的Visual Studio 2010中的Windows 7 64位多监视器系统上尝试过此操作,并且它运行正常。

唯一的区别是我的MessageBox.Show没有接受'this'对象。

您使用的是System.Windows.MessageBox吗?

可能只需要Windows更新和/或重新安装.NET框架。