2
votes

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);
}
1
Strange... Without code it will hard to find problem sourceSpawn
This might prove a useful read.Shawn Mehan
Do you see this problem in the context of a new console application that only attempts to show a message box?Drew Noakes
@DrewNoakes: I have a different app (A WinForm app) that uses System.Windows.Forms.MessageBox, and it works just fine, if that's what you're asking. It also works fine in a different WPF app I have.Rabid Penguin
Yes that was what I was asking. What happens if you pause VS when debugging the app with the dialog displayed? Is the message pump/loop still running?Drew Noakes

1 Answers

1
votes

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.