MessageBox pops up behind ComboBox drop down list, obscuring content in MessageBox

ε祈祈猫儿з 提交于 2019-12-24 15:27:52

问题


In a project I am working on, I have a ComboBox with dates that calculates the persons age depending on certain other criteria elsewhere in the application.

If the user selects a date, we pop up a notification to the user that we changed a few things on the form due to this.

As you can see in the picture, the combobox's items end up still staying on top of the messagebox when it pops up. The user can still click OK, and can move the box, but this is an odd way to present information to the user.

Is there a way to pop up the message box above this list, or hide the list before the messagebox comes up? I tried setting IsDropDownOpen, but that doesn't work.

Update: The MessageBox.Show event happens in the selection changed, which is why I figured it hadn't closed the drop down yet. How could one get around this though?

Update 2: Code I currently have goes like this. ComboBox uses a 'LostFocus' event (to handle typing and/or selecting) to call a CheckDOB method. CheckDOB is where I then show the MessageBox


回答1:


Well I can't reprodouce your issue, but I believe that using the Dispatcher can help.

Try this:

VB.NET

  Private Sub ComboBox_SelectionChanged(sender As System.Object, e As System.Windows.Controls.SelectionChangedEventArgs)
        'Do what you need..
        Me.Dispatcher.BeginInvoke(Sub()
                                      MessageBox.Show("Message", "Caption", MessageBoxButton.OK, MessageBoxImage.Information)
                                  End Sub)
    End Sub

C#

private void ComboBox_SelectionChanged(System.Object sender, System.Windows.Controls.SelectionChangedEventArgs e)
{
    //Do what you need..
     Dispatcher.BeginInvoke(new ThreadStart(() =>
     {

         MessageBox.Show("Message", "Caption", MessageBoxButton.OK, MessageBoxImage.Information); 

      }));
}


来源:https://stackoverflow.com/questions/8126911/messagebox-pops-up-behind-combobox-drop-down-list-obscuring-content-in-messageb

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!