Beispiel #1
0
        protected override void ProcessRecord()
        {
            base.ProcessRecord();

            // 20140312
            // if (InputObject.Current.ControlType == classic.ControlType.Window)
            if (InputObject.GetCurrent().ControlType == classic.ControlType.Window)
            {
                // 20131208
                // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                // WindowPattern windowPattern = InputObject.GetCurrentPattern(classic.WindowPattern.Pattern) as WindowPattern;
                // !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
                IWindowPattern windowPattern = InputObject.GetCurrentPattern <IWindowPattern>(classic.WindowPattern.Pattern);

                try
                {
                    switch (PatternName.ToLower())
                    {
                    case "close":
                        windowPattern.Close();
                        break;

                    case "maximize":
                        windowPattern.SetWindowVisualState(classic.WindowVisualState.Maximized);
                        break;

                    case "minimize":
                        windowPattern.SetWindowVisualState(classic.WindowVisualState.Minimized);
                        break;

                    case "restore":
                        windowPattern.SetWindowVisualState(classic.WindowVisualState.Normal);
                        break;
                    }
                }
                catch (InvalidOperationException)
                {
                    ArgumentException ex = new ArgumentException("Target window doesn't support '" + PatternName + "' pattern.");
                    ThrowTerminatingError(new ErrorRecord(ex, "WrongInputObject", ErrorCategory.InvalidArgument, null));
                }
            }
            else
            {
                ArgumentException ex = new ArgumentException("Cannot call WindowPattern on object that is not a Window.");
                ThrowTerminatingError(new ErrorRecord(ex, "WrongInputObject", ErrorCategory.InvalidArgument, null));
            }
        }