本文整理汇总了C#中System.Windows.Automation.AutomationElement.TryGetCurrentPattern方法的典型用法代码示例。如果您正苦于以下问题:C# AutomationElement.TryGetCurrentPattern方法的具体用法?C# AutomationElement.TryGetCurrentPattern怎么用?C# AutomationElement.TryGetCurrentPattern使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Automation.AutomationElement
的用法示例。
在下文中一共展示了AutomationElement.TryGetCurrentPattern方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TryGetPattern
protected object TryGetPattern(AutomationPattern pattern,AutomationElement elementNeedToGet = null)
{
elementNeedToGet = elementNeedToGet ?? this.self;
object returnPattern;
elementNeedToGet.TryGetCurrentPattern(pattern, out returnPattern);
return returnPattern ?? null;
}
示例2: GetSelectionItemPattern
//获取选择框元素
public static SelectionItemPattern GetSelectionItemPattern(AutomationElement element)
{
object currentPattern;
if (!element.TryGetCurrentPattern(SelectionItemPattern.Pattern, out currentPattern))
{
throw new Exception(string.Format("Element with AutomationId '{0}' and Name '{1}' does not support the SelectionItemPattern.", element.Current.AutomationId, element.Current.Name));
}
return currentPattern as SelectionItemPattern;
}
示例3: ValidateControlForTogglePattern
private static TogglePattern ValidateControlForTogglePattern(AutomationElement element)
{
object togglePattern = null;
bool isValid = element.TryGetCurrentPattern(TogglePattern.Pattern, out togglePattern);
if (isValid)
{
return (TogglePattern)togglePattern;
}
else
{
throw new InvalidOperationException("Invalid operation");
}
}
示例4: ValidateControlForSelectionPattern
private static SelectionItemPattern ValidateControlForSelectionPattern(AutomationElement element)
{
object selPattern = null;
bool isValid = element.TryGetCurrentPattern(SelectionItemPattern.Pattern, out selPattern);
if (isValid)
{
return (SelectionItemPattern)selPattern;
}
else
{
throw new InvalidOperationException("Invalid operation");
}
}
示例5: ValidateButtonControl
private static InvokePattern ValidateButtonControl(AutomationElement element)
{
object invPattern = null;
bool isValid = element.TryGetCurrentPattern(InvokePattern.Pattern,out invPattern);
if (isValid)
{
return (InvokePattern)invPattern;
}
else
{
throw new InvalidOperationException("Invalid operation");
}
}
示例6: ValidateTextControl
private static ValuePattern ValidateTextControl(AutomationElement element)
{
object valPattern = null;
bool isValid = element.TryGetCurrentPattern(ValuePattern.Pattern,out valPattern);
if (isValid)
{
return (ValuePattern)valPattern;
}
else
{
throw new InvalidOperationException("Invalid operation");
}
}
示例7: ValidateExpandCollapseControl
private static ExpandCollapsePattern ValidateExpandCollapseControl(AutomationElement element)
{
object expColPattern = null;
bool isValid = element.TryGetCurrentPattern(ExpandCollapsePattern.Pattern, out expColPattern);
if (isValid)
{
return (ExpandCollapsePattern)expColPattern;
}
else
{
throw new InvalidOperationException("Invalid operation");
}
}
示例8: IsMenuChecked
private int IsMenuChecked(AutomationElement menuHandle)
{
if (menuHandle == null)
{
LogMessage("Invalid menu handle");
return 0;
}
Object pattern = null;
if (menuHandle.TryGetCurrentPattern(LegacyIAccessiblePattern.Pattern,
out pattern))
{
int isChecked;
uint state = ((LegacyIAccessiblePattern)pattern).Current.State;
// Use fifth bit of current state to determine menu item is checked or not checked
isChecked = (state & 16) == 16 ? 1 : 0;
LogMessage("IsMenuChecked: " + menuHandle.Current.Name + " : " + "Checked: " +
isChecked + " : " + "Current State: " + state);
pattern = null;
return isChecked;
}
else
LogMessage("Unable to get LegacyIAccessiblePattern");
return 0;
}
示例9: SelectListItem
private bool SelectListItem(AutomationElement element, String itemText,
bool verify = false)
{
if (element == null || String.IsNullOrEmpty(itemText))
{
throw new XmlRpcFaultException(123,
"Argument cannot be null or empty.");
}
LogMessage("SelectListItem Element: " + element.Current.Name +
" - Type: " + element.Current.ControlType.ProgrammaticName);
Object pattern = null;
AutomationElement elementItem;
try
{
elementItem = utils.GetObjectHandle(element, itemText);
if (elementItem != null)
{
LogMessage(elementItem.Current.Name + " : " +
elementItem.Current.ControlType.ProgrammaticName);
if (verify)
{
bool status = false;
if (elementItem.TryGetCurrentPattern(SelectionItemPattern.Pattern,
out pattern))
{
status = ((SelectionItemPattern)pattern).Current.IsSelected;
}
if (element.TryGetCurrentPattern(ExpandCollapsePattern.Pattern,
out pattern))
{
LogMessage("ExpandCollapsePattern");
element.SetFocus();
((ExpandCollapsePattern)pattern).Collapse();
}
return status;
}
if (elementItem.TryGetCurrentPattern(ScrollItemPattern.Pattern,
out pattern))
{
LogMessage("ScrollItemPattern");
((ScrollItemPattern)pattern).ScrollIntoView();
}
if (elementItem.TryGetCurrentPattern(SelectionItemPattern.Pattern,
out pattern))
{
LogMessage("SelectionItemPattern");
//((SelectionItemPattern)pattern).Select();
// NOTE: Work around, as the above doesn't seem to work
// with UIAComWrapper and UIAComWrapper is required
// to Edit value in Spin control
return utils.InternalClick(elementItem);
}
else if (elementItem.TryGetCurrentPattern(ExpandCollapsePattern.Pattern,
out pattern))
{
LogMessage("ExpandCollapsePattern");
((ExpandCollapsePattern)pattern).Expand();
element.SetFocus();
return true;
}
else
{
throw new XmlRpcFaultException(123,
"Unsupported pattern.");
}
}
}
catch (Exception ex)
{
LogMessage(ex);
if (ex is XmlRpcFaultException)
throw;
else
throw new XmlRpcFaultException(123,
"Unhandled exception: " + ex.Message);
}
finally
{
pattern = null;
elementItem = null;
}
throw new XmlRpcFaultException(123,
"Unable to find item in the list: " + itemText);
}
示例10: InsertTextUsingUiAutomation
/// --------------------------------------------------------------------
/// <summary>
/// Inserts a string into each text control of interest.
/// </summary>
/// <param name="element">A text control.</param>
/// <param name="value">The string to be inserted.</param>
/// --------------------------------------------------------------------
private void InsertTextUsingUiAutomation(AutomationElement element,
string value)
{
try
{
// Validate arguments / initial setup
if (value == null)
throw new ArgumentNullException(
"String parameter must not be null.");
if (element == null)
throw new ArgumentNullException(
"AutomationElement parameter must not be null");
// A series of basic checks prior to attempting an insertion.
//
// Check #1: Is control enabled?
// An alternative to testing for static or read-only controls
// is to filter using
// PropertyCondition(AutomationElement.IsEnabledProperty, true)
// and exclude all read-only text controls from the collection.
if (!element.Current.IsEnabled)
{
throw new InvalidOperationException(
"The control with an AutomationID of "
+ element.Current.AutomationId
+ " is not enabled.\n\n");
}
// Check #2: Are there styles that prohibit us
// from sending text to this control?
if (!element.Current.IsKeyboardFocusable)
{
throw new InvalidOperationException(
"The control with an AutomationID of "
+ element.Current.AutomationId
+ "is read-only.\n\n");
}
// Once you have an instance of an AutomationElement,
// check if it supports the ValuePattern pattern.
object valuePattern = null;
// Control does not support the ValuePattern pattern
// so use keyboard input to insert content.
//
// NOTE: Elements that support TextPattern
// do not support ValuePattern and TextPattern
// does not support setting the text of
// multi-line edit or document controls.
// For this reason, text input must be simulated
// using one of the following methods.
//
if (!element.TryGetCurrentPattern(
ValuePattern.Pattern, out valuePattern))
{
_feedbackText.Append("The control with an AutomationID of ")
.Append(element.Current.AutomationId)
.Append(" does not support ValuePattern.")
.AppendLine(" Using keyboard input.\n");
// Set focus for input functionality and begin.
element.SetFocus();
// Pause before sending keyboard input.
Thread.Sleep(100);
// Delete existing content in the control and insert new content.
SendKeys.SendWait("^{HOME}"); // Move to start of control
SendKeys.SendWait("^+{END}"); // Select everything
SendKeys.SendWait("{DEL}"); // Delete selection
SendKeys.SendWait(value);
}
// Control supports the ValuePattern pattern so we can
// use the SetValue method to insert content.
else
{
_feedbackText.Append("The control with an AutomationID of ")
.Append(element.Current.AutomationId)
.Append((" supports ValuePattern."))
.AppendLine(" Using ValuePattern.SetValue().\n");
// Set focus for input functionality and begin.
element.SetFocus();
((ValuePattern) valuePattern).SetValue(value);
}
}
catch (ArgumentNullException exc)
{
_feedbackText.Append(exc.Message);
}
//.........这里部分代码省略.........
示例11: InsertTextIntoElement
/// <summary>
/// Inserts the specified string value into the control
/// referenced by the element
/// </summary>
/// <param name="element">the element into which to insert text</param>
/// <param name="value">text to insert</param>
public static void InsertTextIntoElement(AutomationElement element, string value)
{
if (element == null || value == null)
{
return;
}
try
{
if (!element.Current.IsEnabled || !element.Current.IsKeyboardFocusable)
{
Log.Debug("Control not enabled or keyboard focusable. AutomationID " + element.Current.AutomationId);
return;
}
object valuePattern;
if (!element.TryGetCurrentPattern(ValuePattern.Pattern, out valuePattern))
{
element.SetFocus();
SendKeys.SendWait(value);
}
else
{
element.SetFocus();
((ValuePattern)valuePattern).SetValue(value);
}
}
catch (Exception ex)
{
Log.Debug(ex.ToString());
}
}
示例12: Pattern
internal static BasePattern Pattern(AutomationElement automationElement, AutomationPattern pattern)
{
object patternObject;
if (automationElement.TryGetCurrentPattern(pattern, out patternObject))
{
return (BasePattern) patternObject;
}
return null;
}
示例13: TryGetInvokePattern
/// <summary>
/// Tries to get the invoke pattern (if available)
/// </summary>
/// <param name="automationElement">The automation element to get the pattern from</param>
/// <param name="pattern">The pattern that was retrieved</param>
/// <returns>True if the pattern was retrieved, false otherwise</returns>
private bool TryGetInvokePattern(AutomationElement automationElement, out InvokePattern pattern)
{
object invokePattern;
if(automationElement.TryGetCurrentPattern(InvokePattern.Pattern, out invokePattern))
{
pattern = invokePattern as InvokePattern;
return pattern != null;
}
pattern = null;
return false;
}
示例14: TS_CloseWindow
/// -------------------------------------------------------------------
/// <summary></summary>
/// -------------------------------------------------------------------
private void TS_CloseWindow(AutomationElement element, CheckType checkType)
{
object wpObject = null;
WindowPattern wp = null;
if (true == element.TryGetCurrentPattern(WindowPattern.Pattern, out wpObject))
{
wp = wpObject as WindowPattern;
if (wp == null)
ThrowMe(checkType, "Could not find the WindowPattern");
wp.Close();
Comment("Called WindowPattern.Close() on the element");
}
m_TestStep++;
}
示例15: IsElementSelected
private bool IsElementSelected(AutomationElement element)
{
object pattern;
if (element.TryGetCurrentPattern(TogglePattern.Pattern, out pattern))
{
var state = ((TogglePattern)pattern).Current.ToggleState;
return state != ToggleState.Off;
}
else
{
return false;
}
}