///////////////////////////////////////////////////////////////////////////////////////////////////// // PUBLIC PROCEDURES ///////////////////////////////////////////////////////////////////////////////////////////////////// /// <summary> /// Occurs when a key is pressed while the control has focus. /// </summary> /// <param name="e">A <see cref="KeyEventArgs"/> that contains the event data.</param> protected override void OnKeyDown(KeyEventArgs e) { if (e == null) { throw new ArgumentNullException("e"); } // Call the base method base.OnKeyDown(e); if (!e.Handled) { switch (e.Key) { case Key.Escape: // Ensure the overlay is closed when Esc is pressed if (WindowChrome.GetIsOverlayVisible(window)) { WindowChrome.SetIsOverlayVisible(window, false); } break; } } }