gyurisc
gyurisc

Reputation: 11492

How do you close open dialogs in a silverlight app?

I have an automatic-lock functionality in my Silverlight app that needs to lock the screen after a certain period. The problem is that open dialogs remains open even if the app is locked.

How do I close these dialogs programatically?

Upvotes: 1

Views: 651

Answers (2)

Jignesh.Raj
Jignesh.Raj

Reputation: 5987

you should add this like :

 dialog.DialogResult = false;
 dialog.Close();

Upvotes: 1

gyurisc
gyurisc

Reputation: 11492

I use the following code snippet to close open dialogs in my silverlight app.

    UIElement ui = App.Current.RootVisual;
    foreach (var popup in VisualTreeHelper.GetOpenPopups())
    {
      if (popup != null)
      {
        System.Windows.Controls.ChildWindow dialog = popup.Child as System.Windows.Controls.ChildWindow;

        if (dialog != null)
        {
          dialog.DialogResult = false;
          dialog.Close();
        }
      }
    }

This only works in Silverlight 4 or newer.

Upvotes: 0

Related Questions