Issue When Using in App.xaml.cs


Using WPFMessageBox to display messages from your application class constructor causes the end-user styling to not be used. I imagine the application resources have not been loaded at this point.
The default style of the message box is a little choppy. Icons are displayed in different sizes (some even get clipped), and the message text is appears in the middle of the window when no icon is used because the icon space is not properly collapsed.
I had to define a style in the WPFMessageBoxWindow.xaml file in order to get the default behavior I desired, but this style then overrides any styles applied in the end-user application. So I also had to add a "useDefaultStyle" boolean toggle to all of the Show methods that would determine whether or not to clear the window resources before ShowDialog is called in the codebehind.
I am now able to to display the WPFMessageBox in the application codebehind and retain proper styling. I am also considering ditching the boolean toggle and, instead, just passing a Style parameter to the Show methods. This style can then be added to the window resources before ShowDialog is called, thereby allowing different styles to be used depending on the situation (i.e. sometimes I would like the YesNo buttons to instead be SaveDiscard buttons).


kallep wrote Feb 19, 2015 at 2:04 PM

I solved this by manually loading my own style:
ResourceDictionary messageboxStyle = (ResourceDictionary)Application.LoadComponent(new Uri("Resources/Style/MessageBoxStyle.xaml", UriKind.Relative));
My style is in a ResourceDictionary in MessageBoxStyle.xaml. Hope this can help someone.