0

I am trying Change the Content of ContentControl when a DataGrid is double clicked with the Following Code:

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

Which Works ok and the content is loaded, however if I remove the message box i recieve the following error:

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

How can I remove this message box and still have the content load properly ?

Thank You.

Praxiom
  • 578
  • 1
  • 8
  • 21
  • Can you share the code within the constructor for `DocumentView` – Ryan Thomas May 07 '21 at 08:22
  • @RyanThomas, I think this thread has it: https://stackoverflow.com/questions/67416924/empty-rows-in-wpf-datagrid – EldHasp May 07 '21 at 08:30
  • Put a breakpoint on the line `mainWindow.contentControl.Content = ...` and then step by step (F11) go through the code until you find the line throwing an exception. Report the result. – EldHasp May 07 '21 at 08:33
  • It Runs through the constructor of DocumentView Ok, Crashes on/after the closing bracket of the click event – Praxiom May 07 '21 at 08:41

1 Answers1

0

I removed the Event From Double Click on the Grid and placed it under a button as follows:

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

This has resolved the issue, though confusingly now Adding the message box back in causes the same exception. perhaps related to this question : WPF : Dispatcher processing has been suspended, but messages are still being processed

Praxiom
  • 578
  • 1
  • 8
  • 21