views:

7641

answers:

6

I'd like to create a popup dialog box in silverlight in which i can manipulate controls, enter data, and return a value. I want it to be modal, so that when it is open, the page "Below" is inaccessible. I havent found an easy way to do this yet. Any suggestions?

+5  A: 

I haven't found a perfect solution either. The closest I have seen is this: Using Popup to create a Dialog class

If it is ok to be non-modal, you can try this tip using HtmlPage.PopupWindow(). How to Popup a Browser Window

Gulzar
+1  A: 

I'm new to the Sliverlight framework and am just starting to figure it out, but I have a similar need for a popup modal dialog box. I just tried an idea that looks promising:

  1. I created a Rectangle (named "Shield") that covers my entire application area. It exists on top of everything in the main app. I set the fill-brush to White, and the opacity-brush to 81% so that the main app contents show through, but lightly (as in disabled). Then make sure the "Shield" is hit-testable. Now, when the "Shield" is visible, it will also, in effect, block all input to the controls below (at least from the mouse, haven't tried keyboard yet). When the app initializes, set the "Shield" visibility to Collapsed. In that state it won't block input to the main app.
  2. The dialog box is then constructed on another canvas element that exists in the z-order on top of the shield. Normally the dialog box will be invisible, but when I need it, I just set the "Shield" to visible, and the dialog to visible. Since the dialog is on top of the "Shield" I get a very modal-like behavior. When the dialog box is closed, make both the dialog canvas and "Shield" canvas invisible again and the main app is again active.

I'm sure this the most brute-force way of doing it and that I will eventually zero in on a more elegant construct, but it works for now.

Kevin
+10  A: 

I know the question asked for a Silverlight 2 solution but in Silverlight 3 (Beta now, RTW in July 2009) there is a built-in ChildWindow that can do everything you're looking for.

Shawn Oster
Here's a guide to child windows: http://www.wintellect.com/CS/blogs/jprosise/archive/2009/04/29/silverlight-3-s-new-child-windows.aspx
Lone Coder
ChildWindows are available now that Silverlight 3 shipped. They are easy to use, have a good usage pattern and look stunning!
Lone Coder
A: 

I had the same requirement and ScottGu's Building a Basic Modal Dialog Using a User Control was the best solution that fit my requirement.

U Senthil Kumar
A: 

Here's a free library that provides one: http://www.vectorlight.net/demos/popup_dialogs.aspx

Lone Coder