Beispiel #1
0
        private void OnButtonUp(object sender, ButtonEventArgs e)
        {
            // Show a modal dialog window

            // Create and show new window
            SecondWindow wnd = new SecondWindow();
            wnd.Visibility = Visibility.Visible;
            wnd.Topmost = true; // move on top of all others

            DispatcherFrame modalFrame = new DispatcherFrame();

            // Create a handler that will terminate the loop when the window will be hidden
            PropertyChangedEventHandler handler = delegate
            {
                if (wnd.Visibility != Visibility.Visible) // when the windows was hidden
                    modalFrame.Continue = false; // tell the frame to exit the loop
            };

            wnd.IsVisibleChanged += handler; // add handler to terminate the loop
            Dispatcher.PushFrame(modalFrame); // start the loop and block the calling thread
            // Here we go when the modal dialog was closed
            wnd.IsVisibleChanged -= handler; // remove handler
        }