System.Windows.Automation.AutomationElement.TryGetCurrentPattern C# (CSharp) Method

TryGetCurrentPattern() public method

public TryGetCurrentPattern ( AutomationPattern pattern, object &patternObject ) : bool
pattern AutomationPattern
patternObject object
return bool
        public bool TryGetCurrentPattern(AutomationPattern pattern, out object patternObject)
        {
            patternObject = null;
            Utility.ValidateArgumentNonNull(pattern, "pattern");
            try
            {
                object nativePattern = this._obj.GetCurrentPattern(pattern.Id);
                patternObject = Utility.WrapObjectAsPattern(this, nativePattern, pattern, false /* cached */);
                return (patternObject != null);
            }
            catch (System.Runtime.InteropServices.COMException e)
            {
                Exception newEx; if (Utility.ConvertException(e, out newEx)) { throw newEx; } else { throw; }
            }

        }

Usage Example

Example #1
0
 public static bool CanExpandElement(this AutomationElement el, ControlType elementType)
 {
     if (elementType == ControlType.SplitButton || elementType == ControlType.Button || elementType == ControlType.MenuItem)
     {
         object ecPattern;
         if (el.TryGetCurrentPattern(LegacyIAccessiblePattern.Pattern, out ecPattern))
         {
             uint state = ((LegacyIAccessiblePattern)ecPattern).Current.State;
             if ((state & 0x40000000) != 0)
             {
                 return(true);
             }
         }
     }
     else if (elementType == ControlType.ComboBox)
     {
         object ecPattern;
         if (el.TryGetCurrentPattern(LegacyIAccessiblePattern.Pattern, out ecPattern))
         {
             uint state = ((LegacyIAccessiblePattern)ecPattern).Current.State;
             if ((state & 0x400) != 0 || (state & 0x200) != 0)
             {
                 return(true);
             }
         }
         var buttonCondition = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Button);
         var button          = el.FindFirst(TreeScope.Children, buttonCondition);
         if (button != null)
         {
             return(true);
         }
     }
     return(false);
 }
All Usage Examples Of System.Windows.Automation.AutomationElement::TryGetCurrentPattern