TextPatternRange.FindAttribute Metod
Definition
Viktigt
En del information gäller för förhandsversionen av en produkt och kan komma att ändras avsevärt innan produkten blir allmänt tillgänglig. Microsoft lämnar inga garantier, uttryckliga eller underförstådda, avseende informationen som visas här.
Returnerar en textområdesunderuppsättning som har det angivna attributvärdet.
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
Parametrar
- attribute
- AutomationTextAttribute
Attributet som du vill söka efter.
- value
- Object
Attributvärdet som du vill söka efter. Det här värdet måste matcha den typ som angetts för attributet.
- backward
- Boolean
true om det senast förekommande textintervallet ska returneras i stället för det första. annars false.
Returer
Ett textintervall med ett matchande attribut och attributvärde. annars null (Nothing i Visual Basic).
Exempel
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
Kommentarer
Det finns ingen differentiering mellan dold och synlig text. UI Automation klienter kan använda IsHiddenAttribute för att kontrollera textens synlighet.
Note
Använd DocumentRange för att söka i hela dokumentet.