1

If the user clicks on the overlay, I want the ChildWindow to automatically close and return the user to the main screen.

Is there a property that controls this? If not, is there a way to attach a click handler to the overlay?

Unheilig
  • 16,196
  • 193
  • 68
  • 98
Jonathan Allen
  • 68,373
  • 70
  • 259
  • 447
  • 2
    Possible duplicate: http://stackoverflow.com/questions/5728678/close-childwindows-in-silverlight-with-a-click-outside-of-it – Ekk Oct 29 '11 at 18:39

1 Answers1

4

Turns out you can get a reference to the overlay right after it is created. After that it is a simple matter of attaching the event handler.

    private void Overlay_MouseButtonDown(object sender, MouseButtonEventArgs e)
    {
        this.Close();
    }

    public override void OnApplyTemplate()
    {
        base.OnApplyTemplate();
        var overlay = (Grid)GetTemplateChild("Overlay");
        overlay.MouseLeftButtonDown += Overlay_MouseButtonDown;
        overlay.MouseRightButtonDown += Overlay_MouseButtonDown;
    }
Jonathan Allen
  • 68,373
  • 70
  • 259
  • 447