/// <summary>
        /// QueryStatus handler called to update the status of the menu items. Does some
        /// basic validation before calling the commands QueryStatusCommand to update
        /// its state
        /// </summary>
        protected static void QueryStatusHandler(object sender, EventArgs e)
        {
            DynamicMenuCommand command = sender as DynamicMenuCommand;

            if (command == null)
            {
                return;
            }

            int cmdIndex = command.CurrentIndex;

            if (cmdIndex >= 0 && cmdIndex < command.MaxCount)
            {
                // Only return if command was handled
                if (command.QueryStatusCommand(cmdIndex, e))
                {
                    // We want to make sure to clear the matched commandid.
                    command.MatchedCommandId = 0;
                    return;
                }
            }
            // If we get this far, hide the command
            command.Visible          = false;
            command.Enabled          = false;
            command.MatchedCommandId = 0;
        }
        /// <summary>
        /// Exec handler called when one of the menu items is selected. Does some
        /// basic validation before calling the commands QueryStatusCommand to update
        /// its state
        /// </summary>
        protected static void ExecHandler(object sender, EventArgs e)
        {
            DynamicMenuCommand command = sender as DynamicMenuCommand;

            if (command == null)
            {
                return;
            }

            int cmdIndex = command.CurrentIndex;

            if (cmdIndex >= 0 && cmdIndex < command.MaxCount)
            {
                // Only return if command was handled
                if (command.ExecCommand(cmdIndex, e))
                {
                    return;
                }
            }

            // We want to make sure to clear the matched commandid.
            command.MatchedCommandId = 0;
        }