Show a MessageBox in Silverlight 2 Beta 1
Since Silverlight is just a subset of WPF, there are a lot 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 a lot 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