Rabid Penguin
Rabid Penguin

Reputation: 1104

WPF MessageBox not working

In my WPF I've tried System.Windows.MessageBox.Show, System.Windows.Forms.MessageBox.Show, and Xceed.Wpf.Toolkit.MessageBox.Show (from the Wpf Toolkit).

Every one of these methods shows the message box exactly how I want it too. The problem is that none of the buttons work. I click OK, I click cancel, I click the X, none of the buttons do anything. And with the toolkit message box I can't move the message box either. The buttons don't depress either. It's as if they're disabled, but I have no idea why.

EDIT: I'm using Prism and MEF to compose the application. Inside my module I have a view that is being displayed in a region in my Shell Window. The view is a UserControl with a button.

<UserControl>
   <Grid>
      <Button content="click me" Click="Button_OnClick"/>
   </Grid>
</UserControl>

In the code behind I have the OnClick method.

private void Button_OnClick(object sender, RoutedEventArgs e)
{
   System.Windows.MessageBox.Show("test");
}

The message box gets displayed, I can move it, The 'X' glows on mouse over, but neither the 'X' nor the 'OK' button, do anything.

I can provide more code as needed, I just don't want to have to include my whole application...

FIXED The main WPF window had a borderless behavior attached to it that was processing windows messages (WndProc) and it wasn't processing the WM_NCACTIVATE message properly.

NOT WORKING:

case UnsafeNativeConstants.WM_NCACTIVATE:
     handled = true;
     break;

WORKING:

case UnsafeNativeConstants.WM_NCACTIVATE:
     retVal = UnsafeNativeMethods.DefWindowProc(hwnd, UnsafeNativeConstants.WM_NCACTIVATE, new IntPtr(1), new IntPtr(-1));
     handled = true;
     break;

internal static UnsafeNativeMethods
{
    [DllImport("user32", CallingConvention = CallingConvention.Winapi)]
    public static extern IntPtr DefWindowProc([In] IntPtr hwnd, [In] int msg, [In] IntPtr wParam, [In] IntPtr lParam);
}

Upvotes: 2

Views: 2711

Answers (1)

Drew Noakes
Drew Noakes

Reputation: 310802

Try running your app in the debugger and pausing when the dialog is visible to ensure the message pump/loop is still running and is not deadlocked. That's the only reason I can think of that your UI could be unresponsive.

Upvotes: 1

Related Questions