Пример #1
0
        /// <summary>
        /// Determines whether the specified index is selected.
        /// </summary>
        /// <param name="controlHandle">The control handle.</param>
        /// <param name="index">The zero-based index of the tab to select.</param>
        /// <returns>
        ///   <c>true</c> if the specified index is selected; otherwise, <c>false</c>.
        /// </returns>
        ///<exception cref="ProdOperationException">Examine inner exception</exception>
        public static bool TabIsSelected(IntPtr controlHandle, int index)
        {
            bool ret;

            try
            {
                AutomationElement   control = CommonUIAPatternHelpers.Prologue(SelectionPattern.Pattern, controlHandle);
                AutomationElement[] element = SelectionPatternHelper.GetSelection(control);
                int retVal = SelectionItemPatternHelper.FindIndexByItem(control, element[0].Current.Name);

                ret = (retVal == index);
                LogController.ReceiveLogMessage(new LogMessage(ret.ToString()));
                return(ret);
            }
            catch (InvalidOperationException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
            catch (ElementNotAvailableException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
            catch (ArgumentException err)
            {
                throw new ProdOperationException(err.Message, err);
            }
        }
 public static int GetSelectedIndex(IntPtr controlHandle)
 {
     try
     {
         AutomationElement   control = CommonUIAPatternHelpers.Prologue(SelectionPattern.Pattern, controlHandle);
         AutomationElement[] element = SelectionPatternHelper.GetSelection(control);
         int ret = SelectionItemPatternHelper.FindIndexByItem(control, element[0].Current.Name);
         if (ret == -1)
         {
             /* Call native function */
             ret = ProdListBoxNative.GetSelectedIndexNative(controlHandle);
         }
         LogController.ReceiveLogMessage(new LogMessage(ret.ToString(CultureInfo.InvariantCulture)));
         return(ret);
     }
     catch (InvalidOperationException err)
     {
         throw new ProdOperationException(err.Message, err);
     }
     catch (ElementNotAvailableException err)
     {
         throw new ProdOperationException(err.Message, err);
     }
     catch (ArgumentException err)
     {
         throw new ProdOperationException(err.Message, err);
     }
 }
        private static int UiaSelectedIndex(BaseProdControl control)
        {
            AutomationElement[] element = SelectionPatternHelper.SelectedItems(control.UIAElement);
            int retVal = SelectionItemPatternHelper.FindIndexByItem(control.UIAElement, element[0].Current.Name);

            LogController.ReceiveLogMessage(new LogMessage(retVal.ToString(CultureInfo.CurrentCulture)));
            return(retVal);
        }
        /// <summary>
        /// Gets the selected indexes using UIA
        /// </summary>
        /// <param name="control">The base ProdUI control</param>
        /// <returns>
        /// A List of all the indexes of currently selected list items.
        /// </returns>
        private static Collection <int> UiaGetSelectedIndexes(BaseProdControl control)
        {
            if (!UiaCanSelectMultiple(control))
            {
                throw new ProdOperationException("Does not support multiple selection");
            }

            AutomationElement[] selectedItems = SelectionPatternHelper.SelectedItems(control.UIAElement);
            Collection <object> retList       = new Collection <object> {
                (selectedItems)
            };
            Collection <int> selectedIndexes = new Collection <int>();

            foreach (AutomationElement item in selectedItems)
            {
                selectedIndexes.Add(SelectionItemPatternHelper.FindIndexByItem(control.UIAElement, item.Current.Name));
            }
            LogController.ReceiveLogMessage(new LogMessage("Selected Indexes", retList));
            return(selectedIndexes);
        }