TextPatternRange.GetAttributeValue(AutomationTextAttribute) 方法     
定义
重要
一些信息与预发行产品相关,相应产品在发行之前可能会进行重大修改。 对于此处提供的信息,Microsoft 不作任何明示或暗示的担保。
返回整个文本范围内指定特性的值。
public:
 System::Object ^ GetAttributeValue(System::Windows::Automation::AutomationTextAttribute ^ attribute);public object GetAttributeValue(System.Windows.Automation.AutomationTextAttribute attribute);member this.GetAttributeValue : System.Windows.Automation.AutomationTextAttribute -> objPublic Function GetAttributeValue (attribute As AutomationTextAttribute) As Object参数
- attribute
- AutomationTextAttribute
文本特性。
返回
返回指定特性的值。 例如,GetAttributeValue(TextPattern.FontNameAttribute) 将返回一个表示文本范围的字体名称(如果唯一)的字符串,而 GetAttributeValue(TextPattern.IsItalicAttribute) 将返回一个布尔值。
如果指定特性的值在文本范围内会发生变化,则返回 MixedAttributeValue。
如果提供程序或控件不支持指定的特性,则返回 NotSupported。
例外
如果指定的特性无效。
示例
 private Object AttributeValueFromSelection(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[] currentSelection = textpatternPattern.GetSelection();
    // Is 'italic'?
    return currentSelection[0].GetAttributeValue(TextPattern.IsItalicAttribute);
}
Private Function AttributeValueFromSelection(ByVal target As AutomationElement) As Object
    ' 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()
    ' Is 'italic'?
    Return currentSelection(0).GetAttributeValue(TextPattern.IsItalicAttribute)
End Function
注解
隐藏文本和可见文本之间没有区别。 UI 自动化客户端可以使用 IsHiddenAttribute 检查文本可见性。