protected override void Invoke(object parameter)
        {
            var args = parameter as InteractionRequestedEventArgs;

            if (args != null)
            {
                var notificationWithServicesAndState = args.Context as NotificationWithServicesAndState;

                if (notificationWithServicesAndState == null ||
                    notificationWithServicesAndState.AudioService == null ||
                    notificationWithServicesAndState.DictionaryService == null)
                {
                    throw new ApplicationException(Resources.REQUIRED_SERVICES_NOT_PASSED_TO_MANAGEMENT_WINDOW);
                }

                var childWindow = new ManagementWindow(notificationWithServicesAndState.AudioService, notificationWithServicesAndState.DictionaryService);

                EventHandler closeHandler = null;
                closeHandler = (sender, e) =>
                {
                    childWindow.Closed -= closeHandler;
                    args.Callback();
                };
                childWindow.Closed += closeHandler;

                var parentWindow = AssociatedObject != null
                    ? AssociatedObject as Window ?? VisualAndLogicalTreeHelper.FindVisualParent <Window>(AssociatedObject)
                    : null;

                bool parentWindowHadFocus = false;
                if (parentWindow != null &&
                    notificationWithServicesAndState.ModalWindow)
                {
                    childWindow.Owner    = parentWindow; //Setting the owner preserves the z-order of the parent and child windows when the focus is shifted back to the parent (otherwise the child popup will be hidden)
                    parentWindowHadFocus = parentWindow.IsFocused;
                }

                if (notificationWithServicesAndState.ModalWindow)
                {
                    Log.Info("Showing Management Window (modal)");
                    childWindow.Topmost = true;
                    childWindow.ShowDialog();
                }
                else
                {
                    Log.Info("Showing Management Window (non-modal)");
                    childWindow.Show();
                }

                if (parentWindow != null &&
                    notificationWithServicesAndState.ModalWindow)
                {
                    if (parentWindowHadFocus)
                    {
                        Log.Debug("Parent Window was previously focussed - giving it focus again.");
                        parentWindow.Focus();
                    }
                }
            }
        }
예제 #2
0
    static void Init()
    {
        // Get existing open window or if none, make a new one:
        ManagementWindow window = (ManagementWindow)GetWindow(typeof(ManagementWindow));

        window.Show();
    }