Search code examples
c#wpfmessagebox

Showing a messagebox from within a TableRowGroup inherited class


I have a class that inherits from TableRowGroup to extend the TableRowGroup's functionality. This works perfectly fine, the issue i am having is when I try to show a message box from this class. The class acts like nothing in the code ever happenned and just shows the basics coming from the xaml.

Is there anything special concerning MessageBox called from within a class like this?

Here is how I call my MessageBox, it's pretty basic:

MessageBox.Show(message, "Title", MessageBoxButton.OK, MessageBoxImage.Warning);

Solution

  • I may be wrong but I think you are messing something by doing things in different UI threads (MessageBox is from the standard Windows Forms and TableRowGroup is from WPF). Try this:

    Task.Factory.StartNew(() => MessageBox.Show(message, "Title", MessageBoxButton.OK, MessageBoxImage.Warning));
    

    I had the same issue with one of my colleague and it solved the problem

    If someone can give some precision in the comments of this answer to enlighten me on WPF vs Windows Forms threads, you are welcome ;).