/// <summary>
        /// Shows a CommandContextMenu modally.
        /// </summary>
        ///	<param name="commandManager">The CommandManager to use.</param>
        /// <param name="parentWindow">The parent window.</param>
        /// <param name="position">The position to show the menu, in screen coordinates.</param>
        /// <param name="alternateXPosition">An alternate X-position in case the showing of the
        /// menu results in the menu going offscreen to the right</param>
        /// <param name="commandContextMenuDefinition">The CommandContextMenuDefinition of the commands to show in the menu.  These commands must be present in the CommandManager.</param>
        /// <returns>The command that was selected; or null if no command was selected.</returns>
        public static Command ShowModal(CommandManager commandManager, Control parentWindow, Point position, int alternateXPosition, CommandContextMenuDefinition commandContextMenuDefinition)
        {
            //	If the command context menu definition was null, or contained no Command identifiers, we're done.
            Debug.Assert(commandContextMenuDefinition != null, "Cannot show a CommandContextMenu without a CommandContextMenuDefinition");
            if (commandContextMenuDefinition == null || commandContextMenuDefinition.Entries.Count == 0)
            {
                return(null);
            }

            //	Obtain the parent window's context menu.
            ContextMenu parentContextMenu = parentWindow.ContextMenu;

            //	Instantiate the CommandContextMenu from the command context menu definition.
            CommandContextMenu commandContextMenu = new CommandContextMenu(commandManager, commandContextMenuDefinition);

            //	Set the context menu as our parent window's context menu so that keyboard mnemonics work.
            parentWindow.ContextMenu = commandContextMenu;

            //	Run the context menu.
            Command command = commandContextMenu.ShowModal(parentWindow, position, alternateXPosition);

            //	Restore our parent window's contetx menu.
            parentWindow.ContextMenu = parentContextMenu;

            //	Dipose of the context menu.
            commandContextMenu.Dispose();

            //	Return the selected command.
            return(command);
        }
        /// <summary>
        /// Shows a CommandContextMenu modally.
        /// </summary>
        ///	<param name="commandManager">The CommandManager to use.</param>
        /// <param name="parentWindow">The parent window.</param>
        /// <param name="position">The position to show the menu, in screen coordinates.</param>
        /// <param name="alternateXPosition">An alternate X-position in case the showing of the
        /// menu results in the menu going offscreen to the right</param>
        /// <param name="commandContextMenuDefinition">The CommandContextMenuDefinition of the commands to show in the menu.  These commands must be present in the CommandManager.</param>
        /// <returns>The command that was selected; or null if no command was selected.</returns>
        public static Command ShowModal(CommandManager commandManager, Control parentWindow, Point position, int alternateXPosition, CommandContextMenuDefinition commandContextMenuDefinition)
        {
            //	If the command context menu definition was null, or contained no Command identifiers, we're done.
            Debug.Assert(commandContextMenuDefinition != null, "Cannot show a CommandContextMenu without a CommandContextMenuDefinition");
            if (commandContextMenuDefinition == null || commandContextMenuDefinition.Entries.Count == 0)
                return null;

            //	Obtain the parent window's context menu.
            ContextMenu parentContextMenu = parentWindow.ContextMenu;

            //	Instantiate the CommandContextMenu from the command context menu definition.
            CommandContextMenu commandContextMenu = new CommandContextMenu(commandManager, commandContextMenuDefinition);

            //	Set the context menu as our parent window's context menu so that keyboard mnemonics work.
            parentWindow.ContextMenu = commandContextMenu;

            //	Run the context menu.
            Command command = commandContextMenu.ShowModal(parentWindow, position, alternateXPosition);

            //	Restore our parent window's contetx menu.
            parentWindow.ContextMenu = parentContextMenu;

            //	Dipose of the context menu.
            commandContextMenu.Dispose();

            //	Return the selected command.
            return command;
        }
        /// <summary>
        /// Shows a CommandContextMenu modally.
        /// </summary>
        /// <param name="parentWindow">The parent window.</param>
        /// <param name="position">The position to show the menu, in screen coordinates.</param>
        /// <param name="alternateXPosition">An alternate X-position in case the showing of the
        /// menu results in the menu going offscreen to the right</param>
        /// <param name="commandCollection">The CommandCollection to show in the menu.  These commands must be present in the CommandManager.</param>
        /// <param name="commandBar">true if this CommandContextMenu is being shown from a CommandBar; false otherwise.</param>
        /// <returns>The command that was selected; or null if no command was selected.</returns>
        public static Command ShowModal(Control parentWindow, Point position, int alternateXPosition, MenuItem[] menuItems)
        {
            //	If the command collection was null, or contained no Commands, we're done.
            Debug.Assert(menuItems != null, "Cannot show a CommandContextMenu without menu items");
            if (menuItems == null || menuItems.Length == 0)
            {
                return(null);
            }

            //	Obtain the parent window's context menu.
            ContextMenu parentContextMenu = parentWindow.ContextMenu;

            //	Instantiate the CommandContextMenu from the command collection.
            CommandContextMenu commandContextMenu = new CommandContextMenu(menuItems);

            //	Set the context menu as our parent window's context menu so that keyboard mnemonics work.
            parentWindow.ContextMenu = commandContextMenu;

            //	Run the context menu.
            Command command = commandContextMenu.ShowModal(parentWindow, position, alternateXPosition);

            //	Restore our parent window's contetx menu.
            parentWindow.ContextMenu = parentContextMenu;

            //	Dipose of the context menu.
            commandContextMenu.Dispose();

            //	Return the selected command.
            return(command);
        }
        /// <summary>
        /// Shows a CommandContextMenu modally.
        /// </summary>
        /// <param name="parentWindow">The parent window.</param>
        /// <param name="position">The position to show the menu, in screen coordinates.</param>
        /// <param name="alternateXPosition">An alternate X-position in case the showing of the
        /// menu results in the menu going offscreen to the right</param>
        /// <param name="commandCollection">The CommandCollection to show in the menu.  These commands must be present in the CommandManager.</param>
        /// <param name="commandBar">true if this CommandContextMenu is being shown from a CommandBar; false otherwise.</param>
        /// <returns>The command that was selected; or null if no command was selected.</returns>
        public static Command ShowModal(Control parentWindow, Point position, int alternateXPosition, MenuItem[] menuItems)
        {
            //	If the command collection was null, or contained no Commands, we're done.
            Debug.Assert(menuItems != null, "Cannot show a CommandContextMenu without menu items");
            if (menuItems == null || menuItems.Length == 0)
                return null;

            //	Obtain the parent window's context menu.
            ContextMenu parentContextMenu = parentWindow.ContextMenu;

            //	Instantiate the CommandContextMenu from the command collection.
            CommandContextMenu commandContextMenu = new CommandContextMenu(menuItems);

            //	Set the context menu as our parent window's context menu so that keyboard mnemonics work.
            parentWindow.ContextMenu = commandContextMenu;

            //	Run the context menu.
            Command command = commandContextMenu.ShowModal(parentWindow, position, alternateXPosition);

            //	Restore our parent window's contetx menu.
            parentWindow.ContextMenu = parentContextMenu;

            //	Dipose of the context menu.
            commandContextMenu.Dispose();

            //	Return the selected command.
            return command;
        }