語言

TextPatternRange.GetAttributeValue(AutomationTextAttribute) 方法

定義

回傳指定屬性的值,涵蓋整個文字範圍。

public:
 System::Object ^ GetAttributeValue(System::Windows::Automation::AutomationTextAttribute ^ attribute);
public object GetAttributeValue(System.Windows.Automation.AutomationTextAttribute attribute);
member this.GetAttributeValue : System.Windows.Automation.AutomationTextAttribute -> obj
Public 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

備註

隱藏文字與可見文字之間沒有區別。 使用者介面自動化用戶端可以使用 IsHiddenAttribute 來檢查文字可見性。

適用於