Click here to Skip to main content
15,884,388 members
Articles / Desktop Programming / WPF
Tip/Trick

WPF MessageBox Service

Rate me:
Please Sign up or sign in to vote.
4.30/5 (10 votes)
21 Nov 2013CPOL2 min read 40.7K   28   9
A message box service implementation that is based on WPF.

Introduction 

Februrary, 2017.

I have released a ContentDialogService implementation that also supports mocal dialogs through the same API as mentioned in the project below: Here is the link to the CodeProject article:

https://www.codeproject.com/Articles/1170500/A-ContentDialog-in-a-WPF-Desktop-Application

November, 2013:

I have released a message box service implementation that is based on WPF at: https://github.com/Dirkster99/MsgBox.

Image 1

 

See feature description and documentation for full details of the first version.

  • API coverage of standard System.Message box as of .NET 4.0
  • Themable WPF MVVM compliant Message Box Service
  • Localized in several languages
  • Display of Exception Summary and Details
  • 3 Icon sets
  • 2 Window Chrome Styles + Metro Dark and Light themes
  • Hyperlink display
  • Escape Key, Alt-F4, Window Close Button (X) interpretation
  • Forced Choice supported in a nice way  with user notification

Background  

The implementation is a spin off from my editor project: https://github.com/Dirkster99/Edi.

Best thing is the exception display - it helps me when running the release version and still trying to find some issues that may not appear in the debug version:
Image 2

C#
result = Msg.Show(exp, "Unexpected Error",
  MsgBoxButtons.OK, MsgBoxImage.Error, MsgBoxResult.NoDefaultButton,
  "http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=7799028",
  "http://www.codeproject.com/script/Articles/MemberArticles.aspx?amid=7799028",
  "Please click on the link to check if this is a known problem (and report it if not):", null, true); 

Using the code 

The code is rather simple to use (see released demo applications for more details). Start a new WPF application project and reference the MsgBox.DLL. Use, for example, this code:

C#
MsgBoxResult result = Msg.Show("hello world message", "hellow world caption"); 

 

to show a simple message box (see codeplex site for more advanced applications).

Points of Interest 

Other message box service implementations are usually part of a particular framework. So re-using these often does not come without the hassle of having to initialize and use a complex framework when all one wants it to use a message box service. Its sometimes even impossible to use a message box service from a particular framework without having to re-use the complete framework. 

Most frameworks I have seen  do not care about the System.MessageBox API. So, a huge conversion is often required when refactoring for that framework. This is not the case with the MsgBox.

Please let me know if you feel the posted documentation is helpful or if you are missing anything crucial. I would also like to see if anyone finds this useful and does actually use it in their application. Please give me your feedback - the good and the bad - if any - thanks a lot. 

History 

  • 13.11.2013 - Initial posting. 

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Germany Germany
The Windows Presentation Foundation (WPF) and C# are among my favorites and so I developed Edi

and a few other projects on GitHub. I am normally an algorithms and structure type but WPF has such interesting UI sides that I cannot help myself but get into it.

https://de.linkedin.com/in/dirkbahle

Comments and Discussions

 
SuggestionLocalization typo Pin
snalesso21-Nov-13 15:18
snalesso21-Nov-13 15:18 
GeneralRe: Localization typo Pin
Dirk Bahle22-Nov-13 7:48
Dirk Bahle22-Nov-13 7:48 
Questionnice Pin
BillW3319-Nov-13 9:10
professionalBillW3319-Nov-13 9:10 
AnswerRe: nice Pin
Dirk Bahle19-Nov-13 12:43
Dirk Bahle19-Nov-13 12:43 
GeneralRe: nice Pin
BillW3320-Nov-13 8:10
professionalBillW3320-Nov-13 8:10 
GeneralRe: nice Pin
Dirk Bahle21-Nov-13 6:41
Dirk Bahle21-Nov-13 6:41 
General[My vote of 1] This is not an article Pin
r_hyde13-Nov-13 13:03
r_hyde13-Nov-13 13:03 
You've given no implementation details and no information about the benefits of using your MessageBox service implementation over those found in various existing MVVM frameworks. You don't even show any of the source code (just a link to another site where the code can be found). An article is supposed to give the readers some insight into the problem(s) your code solves; the challenges you faced, and the reasons why you solved them in the particular way that you did. Such information gives others the ability to learn something more fundamental than the simple fact that there exists yet another MessageBox component. What you have here doesn't even count as documentation, considering you've only given a simple one-line example of usage (unless, of course, that's all your library has to offer, in which case why bother?).

Please disregard.

modified 14-Nov-13 5:51am.

GeneralRe: [My vote of 1] This is not an article Pin
Dirk Bahle13-Nov-13 13:47
Dirk Bahle13-Nov-13 13:47 
GeneralRe: [My vote of 1] This is not an article Pin
r_hyde13-Nov-13 23:51
r_hyde13-Nov-13 23:51 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.