删除 MessageBox 导致 WPF 应用程序在设置内容时崩溃

Removal of MessageBox Causes WPF Application to Crash on setting Content

我正在尝试使用以下代码双击 DataGrid 时更改 ContentControl 的内容:

    private void homeGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
    {
        if (homeGrid.SelectedItem != null)
        {                
            Document selectedDoc = (Document)homeGrid.SelectedItem;
          
            // Will Crash if this Message Box Removed
                MessageBox.Show(selectedDoc.FilePath);     

            mainWindow.contentControl.Content = new DocumentView(selectedDoc);
        }           
    }

工作正常并且内容已加载,但是如果我删除消息框,我会收到以下错误:

An unhandled exception of type 'System.InvalidOperationException' occurred in WindowsBase.dll
Additional information: Dispatcher processing has been suspended, but messages are still being processed.

如何删除此消息框并仍然正确加载内容?

谢谢。

我删除了双击网格中的事件并将其放在按钮下,如下所示:

   private void Go_Click(object sender, RoutedEventArgs e)
    {
        if (homeGrid.SelectedItem != null)
        {
            Document selectedDoc = (Document)homeGrid.SelectedItem;

            // Will Crash if this Message Box Added?
            //     MessageBox.Show(selectedDoc.FilePath);                            

            mainWindow.contentControl.Content = new DocumentView(selectedDoc);
        }           
    }

这已经解决了问题,但现在令人困惑的是,重新添加消息框会导致相同的异常。可能与这个问题有关:WPF : Dispatcher processing has been suspended, but messages are still being processed