public static class WPFWindowExtensions { public static void ShowNonBlockingModal(this Window window) { var parent = window.Owner; EventHandler parentDeactivate = (_, __) => { window.Activate(); }; parent.Activated += parentDeactivate; EventHandler window_Closed = (_, __) => { parent.Activated -= parentDeactivate; }; window.Show(); } }
I tried to keep it simple to be more readable, however you may add a check for the window.Owner to have a value and throw an exception if it is null, or you may automatically set the owner with the current active window as described in this blog post.
I needed a modal window that let execution continue after it was opened, and this worked perfect right out of the box! Thanks!
ReplyDelete