public static int SelectedItemCount(IntPtr controlHandle)
        {
            try
            {
                AutomationElement control = CommonUIAPatternHelpers.Prologue(SelectionPattern.Pattern, controlHandle);
                if (!SelectionPatternHelper.CanSelectMultiple(control))
                {
                    return(-1);
                }

                AutomationElement[] selectedItems = SelectionPatternHelper.GetSelection(control);

                if (selectedItems == null)
                {
                    if (CanSelectMultiple(controlHandle))
                    {
                        /* Call native function */
                        return(ProdListBoxNative.GetSelectedItemCountNative(controlHandle));
                    }
                }

                if (selectedItems == null)
                {
                    return(-1);
                }
                LogController.ReceiveLogMessage(new LogMessage("List selection count: " + selectedItems.Length));
                return(selectedItems.Length);
            }
            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 NativeGetSelectedItemCount(BaseProdControl control)
 {
     return(ProdListBoxNative.GetSelectedItemCountNative((IntPtr)control.UIAElement.Current.NativeWindowHandle));
 }