One feature I wanted in WPF applications is a good looking message box. But every time I call the MessageBox.Show() method in my apps, the old win forms style message box pops on my screen. Sad part is that the MessageBox class used in WPF goes directly into user32... which makes it impossible to extend the message box and apply some style to make it look more WPF way.
I decided to create a custom message box that looks better than the Win32 one and use in my WPF applications. Special thanks to Christian Moser for the sample to remove the title icon from a WPF window, which I have shamelessly copied in my implementation. The final output is as in the figure.
You can call the WPFMessageBox.Show method as:
__Result = WPFMessageBox.Show("WPF MessageBox", "This options displays a message box with YES, NO, CANCEL option!!!", WPFMessageBoxButtons.YesNoCancel, WPFMessageBoxImage.Question);
Implementation:
public static WPFMessageBoxResult Show(string title, string message, WPFMessageBoxButtons buttonOption, WPFMessageBoxImage image)
{
___MessageBox = new WPFMessageBox();
MessageBoxViewModel __ViewModel = new MessageBoxViewModel(___MessageBox, title, message, buttonOption, image);
___MessageBox.DataContext = __ViewModel;
___MessageBox.ShowDialog();
return ___MessageBox.Result;
}
<Image Source="{Binding MessageImageSource}" HorizontalAlignment="Left" VerticalAlignment="Center" Height="48" Width="48" Margin="10 0 0 0" />
<TextBlock Text="{Binding Message}" Grid.RowSpan="2" Grid.Column="1" TextWrapping="Wrap" TextAlignment="Left" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="10 10 10 10" />
<StackPanel Grid.Row="2" Grid.Column="1" Orientation="Horizontal" VerticalAlignment="Center" HorizontalAlignment="Right" Margin="0 0 5 0">
<Button Content="_Yes" Visibility="{Binding YesNoVisibility}" Command="{Binding YesCommand}" Margin="5 5 5 5" Height="24" Width="80" />
<Button Content="_No" Visibility="{Binding YesNoVisibility}" Command="{Binding NoCommand}" Margin="5 5 5 5" Height="24" Width="80" />
<Button Content="_Cancel" Visibility="{Binding CancelVisibility}" Command="{Binding CancelCommand}" Margin="5 5 5 5" Height="24" Width="80" />
<Button Content="O_K" Visibility="{Binding OkVisibility}" Command="{Binding OkCommand}" Margin="5 5 5 5" Height="24" Width="80" />
<Button Content="_Close" Visibility="{Binding CloseVisibility}" Command="{Binding CloseCommand}" Margin="5 5 5 5" Height="24" Width="80" />
StackPanel>
I have uploaded the source code to codeplex. You can get it from here
http://prajeeshprathap.codeplex.com/SourceControl/PatchList.aspx
http://prajeeshprathap.codeplex.com/SourceControl/PatchList.aspx
Looks good.
ReplyDeleteCan I get the source code.
Have you tried creating a control which has an option to expand an show the inner exception.
Currently the message box control does not have the feature to show the inner exception with an expander. I'll try to add this functionality to the control and post it soon. Thanks for bringing this to my attention.
ReplyDeleteLooks good, please could I have the src?
ReplyDeletechrisblanchard@gmx.co.uk
thanks
This is what I am looking for.
ReplyDeleteThanks!
This is what I am looking for. Thanks!
ReplyDeleteGreat!
ReplyDeleteLooks great. Can I have the source code?
ReplyDeleteVery good, please send source to
ReplyDeleteandersbjuro@hotmail.com
Great. Can you send me the source code? hstoker@vxcompany.com
ReplyDeleteYour custom messagebox is really nice. Can I have the source code please? shortstory@free.fr
ReplyDeleteYour custom messagebox control looks really nice. Can I have the source code please? shortstory@free.fr
ReplyDeleteYour custom messagebox control looks really nice. Can I have the source code please? shortstory@free.fr
ReplyDeleteYour custom messagebox control looks really nice. Can I have the source code please? shortstory@free.fr
ReplyDeleteYour custom messagebox control looks really nice. Can I have the source code please? shortstory@free.fr
ReplyDeleteHello
ReplyDeleteIt looks nice, It would be very great if you send me the source code
Can I use it in a WPF Browser Application
Thanks
Very good job.
ReplyDeleteLooks excatly like what I am looking for !!!
Could I have the source code please ?
Thanks.
Hi cvoisin,
ReplyDeleteCould you please leave your email id for source code?
Really nice your control. Could you send to me the source code, please. shortstory@free.fr
ReplyDeleteCould I get the source code please? crapmail234@gmail.com. Thanks!
ReplyDeletemay i have the source code as well
ReplyDeletethanks alot!
slaked90@yahoo.com.sg
Very interesting article! Can I get the code at tedyusa2000@yahoo.ca
ReplyDeleteHappy New Year!
Good Work.
ReplyDeleteCan I please have the source code? My email address is minnimadan@gmail.com
Very nice work!
ReplyDeleteCould you send the source code to mah@texoapplication.se?
Regards and thanks!
Very nice work!
ReplyDeleteCould you please send the source code to mah@texoapplication.se?
Regards and thanks!
prof_hayalet@hotmail.com
ReplyDeletethanks
Hi Prajeesh,
ReplyDeleteNice work!
r0xz0rz@yahoo.com
Hi Prajeesh
ReplyDeleteWill you please mail me the source
vorstert@gmail.com
Thanks
This looks good. Can you please send me the source code
ReplyDeletepintookhara@gmail.com
Really good job.
ReplyDeleteCould I have the source code please ?
emininam@gmail.com
Emin İnam
thanks
That's a very good idea.
ReplyDeleteCan you send me the source code please?
just.faris@gmail.com
Thanks.
Looks good, could you send me the source code ?
ReplyDeleteb0uncer@sapo.pt
thanks.
hi,
ReplyDeletelooks good, can you send me the sourcecode.
jikubhai@yahoo.com
thanks
Looks good, could you send me the source code ?
ReplyDeletehlisa@walla.co.il
thanks.
Looks good, could you send me the source code ?
ReplyDeletehlisa@walla.co.il
thanks.
Hey, looks great.
ReplyDeleteCould I please get the Source Code?
ecairncross@gmail.com
Thanks
Looks great. Can I have the source code?
ReplyDeletetrialboy@live.cn
Looks great. Can I have the source code?
ReplyDeleteq2onq2@yahoo.com.cn
Thanks
Great job,
ReplyDeleteCan I get the source code.
corneflex@gmail.com
Him great control!
ReplyDeleteCould you please send the source code to simon(dot)wolters(at)gmx(dot)de?
Thank you!
Just what I was looking for, pljames mmm.com thanks!
ReplyDeletegot i was lookin for since 3 days...
ReplyDeletethnx dude....
ur post has really helped me a lot....
That's exactly what I am looking for! Could you please send me the source files to pirlock34@hotmail.com?
ReplyDeleteThanks in advance!!!
can u plz mail me d source code...
ReplyDeletei dint get it the last time u sent...
plz mail it on sagardoshi_7891@yahoo.co.in....
This is what i am looking for Can you please send me the source code to shaikphakeer@yahoo.com
ReplyDeleteThanks
Shaik
Prajeesh,
ReplyDeletePlease send me (cs.3.rich1954@spamgourmet.com) the source code. Thanks in advance!
-R Frainier
Can you please send the source code to join10_2000@yahoo.com.
ReplyDeleteCould I please get the source code? Thanks.
ReplyDelete~ eshoberg + @ + hotmail + . "com"
Please send source code to:
ReplyDeleteseaero@gmail.com
Thanks!
Please send source code to:
ReplyDeletesam_mahanta@msn.com
Thanks in advance!
Hi, This looks like just what I'm looking for. May I have the source code please. Many Thanks in advance.
ReplyDeleteplumbja@yahoo.co.uk
Thanks for the offer - I'd like the source code too pls.
ReplyDeleteBTW, have you thought of posting the code up on CodeProject?
brettg@dodo.com.au
Nice try, but it would be a more helpful resource if you weren't asking people to put their email addresses up on your site to get your source code.
ReplyDeleteHi,
ReplyDeletei'm interresting having your code.
could you email me it at julien.roy@logica.com
thanks
Looks Great!
ReplyDeletePossible if I could get a hand on the source :)
justinwong85@gmail.com
hi. very nice work! could you please send me the source (kostakimu@googlemail.com)? thanks in advance..
ReplyDeleteThat look awesome!
ReplyDeletePlease, could you send me the src?
jelenastankov@gmail.com
Excellent post.
ReplyDeletePlease send me source code also.
Thanks very much.
guy.landingham@verizon.net
Looks great, really helpfull, could you send me the source code?
ReplyDeleteThanks
yogesh_megan@hotmail.com
I'd really love to take a look at the source code. Please, send me it at laserpe.z at gmail.com.
ReplyDeleteThank you in advance!
hi prajeesh, the control looks awesome. good job. Can I hav a look at source code.
ReplyDeleteand my mail Id is Vamsip.net@gmail.com
It looks very nice. Can I get it?
ReplyDeletecool,
ReplyDeletekiveendra@gmail.com
Excelent messagebox, i hope U can send me the source code... Thanks in advance...
ReplyDeletecesarpjc79@hotmail.com
please send me the code to the following e-mail. ramanpk@hotmail.com
ReplyDeleteHi,
ReplyDeleteI'm still waiting for the source code ? Thanks !
telecino@gmail.com
This what exactly I am searching thank you Prajeesh.Please mail source code to me at ravi.avpg@gmail.com
ReplyDeleteVery good, please send source to
ReplyDeletedanshar@bk.ru
Very good, please send source to
ReplyDeletedanshar@bk.ru
I have uploaded the source code to codeplex. You can get it from here
ReplyDeletehttp://prajeeshprathap.codeplex.com/SourceControl/PatchList.aspx
Very Nice!!
ReplyDeleteSaved us hours of works!
Steve
Thanks for sharing the code. While I was testing this, I notice something that is a bit inconsistent with the built in message box:
ReplyDelete- I don't think you are handling the Escape key to close the window.
- And when I close the window using the 'X' button, the WPFMessageBoxResult is always default to Yes. Most of the time, this is okay, but I think it can lead to some expected results.
Your custom messagebox control looks really nice. Can I have the source code please?
ReplyDeletegopalrmahale@gmail.com
Thanks You. Nice to hear that you've found the post useful.
ReplyDelete