TextPatternRange.FindAttribute 方法
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回具有指定特性值的文本范围子集。
public:
System::Windows::Automation::Text::TextPatternRange ^ FindAttribute(System::Windows::Automation::AutomationTextAttribute ^ attribute, System::Object ^ value, bool backward);
public System.Windows.Automation.Text.TextPatternRange FindAttribute (System.Windows.Automation.AutomationTextAttribute attribute, object value, bool backward);
member this.FindAttribute : System.Windows.Automation.AutomationTextAttribute * obj * bool -> System.Windows.Automation.Text.TextPatternRange
Public Function FindAttribute (attribute As AutomationTextAttribute, value As Object, backward As Boolean) As TextPatternRange
参数
- attribute
- AutomationTextAttribute
要搜索的特性。
- value
- Object
要搜索的特性值。 此值必须与为特性指定的类型匹配。
- backward
- Boolean
如果应该返回最后一个匹配的文本范围而不是第一个,则为 true
;否则为 false
。
返回
具有匹配特性和特性值的文本范围;否则为 null(在 Visual Basic 中为 Nothing
)。
示例
private TextPatternRange RangeFromAttribute(AutomationElement target)
{
// Specify the control type we're looking for, in this case 'Document'
PropertyCondition cond = new PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document);
// target --> The root AutomationElement.
AutomationElement textProvider = target.FindFirst(TreeScope.Descendants, cond);
TextPattern textpatternPattern = textProvider.GetCurrentPattern(TextPattern.Pattern) as TextPattern;
if (textpatternPattern == null)
{
Console.WriteLine("Root element does not contain a descendant that supports TextPattern.");
return null;
}
TextPatternRange[] currentSelelction = textpatternPattern.GetSelection();
// Find 'italic' range
return currentSelelction[0].FindAttribute(TextPattern.IsItalicAttribute, true, false);
}
Private Function RangeFromAttribute(ByVal target As AutomationElement) As TextPatternRange
' Specify the control type we're looking for, in this case 'Document'
Dim cond As PropertyCondition = New PropertyCondition(AutomationElement.ControlTypeProperty, ControlType.Document)
' target --> The root AutomationElement.
Dim textProvider As AutomationElement = target.FindFirst(TreeScope.Descendants, cond)
Dim textpatternPattern As TextPattern = CType(textProvider.GetCurrentPattern(TextPattern.Pattern), TextPattern)
If (textpatternPattern Is Nothing) Then
Console.WriteLine("Root element does not contain a descendant that supports TextPattern.")
Return Nothing
End If
Dim currentSelection As TextPatternRange() = textpatternPattern.GetSelection()
Return currentSelection(0).FindAttribute(TextPattern.IsItalicAttribute, True, False)
End Function
注解
隐藏文本和可见文本之间没有区别。 UI 自动化客户端可以使用 IsHiddenAttribute 检查文本可见性。
注意
使用 DocumentRange 搜索整个文档。