1

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?

gyurisc
  • 11,234
  • 16
  • 68
  • 102

2 Answers2

1

you should add this like :

 dialog.DialogResult = false;
 dialog.Close();
Jignesh.Raj
  • 5,776
  • 4
  • 27
  • 56
  • the particular problem here is not the actual closing of the dialog, but to find the reference to the dialog. I need to first find it in the VisualTree from that point closing it works exactly like you described... – gyurisc Jun 29 '13 at 07:54
0

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.

gyurisc
  • 11,234
  • 16
  • 68
  • 102
  • 1
    Set a `DialogResult` and call `Close` can mark your App as disabled (If close animation). Just use one to prevent this... – Tonio Jun 14 '13 at 13:53