共用方式為


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 檢查文字可見度。

適用於