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
73 comments:
Looks good.
Can 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.
Looks good, please could I have the src?
chrisblanchard@gmx.co.uk
thanks
This is what I am looking for.
Thanks!
This is what I am looking for. Thanks!
Great!
Looks great. Can I have the source code?
Very good, please send source to
andersbjuro@hotmail.com
Great. Can you send me the source code? hstoker@vxcompany.com
Your custom messagebox is really nice. Can I have the source code please? shortstory@free.fr
Your custom messagebox control looks really nice. Can I have the source code please? shortstory@free.fr
Your custom messagebox control looks really nice. Can I have the source code please? shortstory@free.fr
Your custom messagebox control looks really nice. Can I have the source code please? shortstory@free.fr
Your custom messagebox control looks really nice. Can I have the source code please? shortstory@free.fr
Hello
It 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.
Looks excatly like what I am looking for !!!
Could I have the source code please ?
Thanks.
Hi cvoisin,
Could 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
Could I get the source code please? crapmail234@gmail.com. Thanks!
may i have the source code as well
thanks alot!
slaked90@yahoo.com.sg
Very interesting article! Can I get the code at tedyusa2000@yahoo.ca
Happy New Year!
Good Work.
Can I please have the source code? My email address is minnimadan@gmail.com
Very nice work!
Could you send the source code to mah@texoapplication.se?
Regards and thanks!
Very nice work!
Could you please send the source code to mah@texoapplication.se?
Regards and thanks!
prof_hayalet@hotmail.com
thanks
Hi Prajeesh,
Nice work!
r0xz0rz@yahoo.com
Hi Prajeesh
Will you please mail me the source
vorstert@gmail.com
Thanks
This looks good. Can you please send me the source code
pintookhara@gmail.com
Really good job.
Could I have the source code please ?
emininam@gmail.com
Emin İnam
thanks
That's a very good idea.
Can you send me the source code please?
just.faris@gmail.com
Thanks.
Looks good, could you send me the source code ?
b0uncer@sapo.pt
thanks.
hi,
looks good, can you send me the sourcecode.
jikubhai@yahoo.com
thanks
Looks good, could you send me the source code ?
hlisa@walla.co.il
thanks.
Looks good, could you send me the source code ?
hlisa@walla.co.il
thanks.
Hey, looks great.
Could I please get the Source Code?
ecairncross@gmail.com
Thanks
Looks great. Can I have the source code?
trialboy@live.cn
Looks great. Can I have the source code?
q2onq2@yahoo.com.cn
Thanks
Great job,
Can I get the source code.
corneflex@gmail.com
Him great control!
Could 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!
got i was lookin for since 3 days...
thnx 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?
Thanks in advance!!!
can u plz mail me d source code...
i 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
Thanks
Shaik
Prajeesh,
Please 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.
Could I please get the source code? Thanks.
~ eshoberg + @ + hotmail + . "com"
Please send source code to:
seaero@gmail.com
Thanks!
Please send source code to:
sam_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.
plumbja@yahoo.co.uk
Thanks for the offer - I'd like the source code too pls.
BTW, 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.
Hi,
i'm interresting having your code.
could you email me it at julien.roy@logica.com
thanks
Looks Great!
Possible 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..
That look awesome!
Please, could you send me the src?
jelenastankov@gmail.com
Excellent post.
Please send me source code also.
Thanks very much.
guy.landingham@verizon.net
Looks great, really helpfull, could you send me the source code?
Thanks
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.
Thank you in advance!
hi prajeesh, the control looks awesome. good job. Can I hav a look at source code.
and my mail Id is Vamsip.net@gmail.com
It looks very nice. Can I get it?
cool,
kiveendra@gmail.com
Excelent messagebox, i hope U can send me the source code... Thanks in advance...
cesarpjc79@hotmail.com
please send me the code to the following e-mail. ramanpk@hotmail.com
Hi,
I'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
Very good, please send source to
danshar@bk.ru
Very good, please send source to
danshar@bk.ru
I have uploaded the source code to codeplex. You can get it from here
http://prajeeshprathap.codeplex.com/SourceControl/PatchList.aspx
Very Nice!!
Saved 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:
- 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?
gopalrmahale@gmail.com
Thanks You. Nice to hear that you've found the post useful.
Post a Comment