Alex Rivera | Logout

How to make ChildWindow blocking

Asked 2009-08-13T17:59:23.467
14

The ChildWindow is a modal window, but it does not block. Is there any way to make it blocking? I basically want a ShowDialog() method that will call ChildWindow.Show() but then not return until the user has closed the ChildWindow. I tried using Monitor.Enter() to block after ChildWindow.Show(), but the ChildWindow never rendered and the browser just hung. Anyone have any ideas?

Edit
Report

2 Answers

0

You could try to always cancel the close event and set the DialogResult later.

void ConfigTemplatePopup_Closing(object sender, System.ComponentModel.CancelEventArgs e)
    {
        if (tmpDialogResult != null || DialogResult == true) return;
        tmpDialogResult = DialogResult; //this is a field
        e.Cancel = true;
        var myMessageBox = new WspMessageBox("Are you sure you want to close?", true);
        myMessageBox.Closed += (s, e2) =>
                                    {
                                        if (wspMessageBox.DialogResult == true)
                                        {
                                            DialogResult = tmpDialogResult;
                                        }else
                                        {
                                            tmpDialogResult = null;
                                        }
                                    };
        myMessageBox.Show();
    }
answered 2011-02-03T10:19:07.650
-1

I hacked away at creating a "blocking" modal dialog, by having a custom control that has a vertical- and horizontal alignment as stretch, and then add that as a child of the layout of the current control.

e.g.

   <Grid x:Name="LayoutRoot" HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
        <Rectangle Fill="LightBlue" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Opacity="0.3" />
    </Grid>

and then in the custom control

Utilities.UITools.MessageBox x = new Utilities.UITools.MessageBox();
x.SetError(e.Result);
this.LayoutRoot.Children.Add(x);

Depending on what has to be displayed in the modal, I dynamically add controls to the modal layout. Clearly, not an elegant solution, but at least it works.

answered 2009-08-20T11:01:15.513

Your Answer