Microsoft Most Valuable Professional

Chris Pietschmann

An MVP From Wisconsin



Show a MessageBox in Silverlight 2 Beta 1

Since Silverlight is just a subset of WPF, there are alot of things missing. One missing thing I found is the System.Windows.MessageBox. I'm a little puzzled as to why they would have left this out, but I imagine MessageBox's are handled very differently in different Operating Systems. It's probably a little work to get it working on both Mac and Windows, but I hope it gets into the final release. It's not a major feature, but one that is used quite often when developing desktop applications, so I can see it being used alot in Silverlight applications.

Anyways, here's a small implementation I wrote that wraps up the JavaScript Alert to give us a basic MessageBox to use for now:

public static class MessageBox
{
    public static void Show(string message)
    {
        HtmlPage.Window.Alert(message);
    }
}

Update 4/2/2008: I updated the above example to use the "HtmlPage.Window.Alert" method instead of the Invoke method; better to use the method that's already in the framework.

Also, here's the above code example in VB.NET:

Module MessageBox
    Public Sub Show(ByVal message As String)
        HtmlPage.Window.Alert(message)
    End Sub
End Module

 

Currently rated 5.0 by 6 people

  • Currently 5/5 Stars.
  • 1
  • 2
  • 3
  • 4
  • 5

Categories: Silverlight
Posted by crpietschmann on Saturday, March 08, 2008 6:13 PM
Permalink | Comments (2) | Post RSSRSS comment feed

Related posts

Comments

Rahul Gangwar in

Thursday, March 27, 2008 6:47 AM

Rahul Gangwar

Nice effort to educate the people. The article is crisp, concise and to the point which attracted me to write comment.

Dave Hickey us

Sunday, March 30, 2008 11:31 PM

Dave Hickey


System.Windows.Browser.HtmlPage.Window.Alert(”Hello World”)

anoriginalidea.wordpress.com/.../

Comments are closed

About the author

I'm Chris Pietschmann, go to the About Me page to learn more about me.

Search

Sponsors

Web.Maps.VE - ASP.NET AJAX Virtual Earth Mapping Server Control

Recent comments

Disclaimer


This work is licensed under a Creative Commons Attribution 3.0 United States License, unless explicitly stated otherwise within the posted content.
© Copyright 2004 - 2008 Chris Pietschmann