TextPatternRange.ExpandToEnclosingUnit(TextUnit) 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將文字範圍擴展至指定的 TextUnit範圍。
public:
void ExpandToEnclosingUnit(System::Windows::Automation::Text::TextUnit unit);
public void ExpandToEnclosingUnit(System.Windows.Automation.Text.TextUnit unit);
member this.ExpandToEnclosingUnit : System.Windows.Automation.Text.TextUnit -> unit
Public Sub ExpandToEnclosingUnit (unit As TextUnit)
參數
- unit
- TextUnit
文本單元。
範例
private void ExpandSelection(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;
}
TextPatternRange[] currentSelection = textpatternPattern.GetSelection();
// Expand selection to include entire document
currentSelection[0].ExpandToEnclosingUnit(TextUnit.Document);
}
Private Sub ExpandSelection(ByVal target As AutomationElement)
' 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
End If
Dim currentSelection As TextPatternRange() = textpatternPattern.GetSelection()
currentSelection(0).ExpandToEnclosingUnit(TextUnit.Document)
End Sub
備註
如果範圍已經是指定單位的精確數量,則保持不變。
為了讓 ExpandToEnclosingUnit 方法成功執行,幕後會執行一連串的動作。
文字範圍會被正規化;也就是說,文字範圍在端點被簡化為退化區間 Start ,使該 End 端點變得多餘。 此步驟是為了消除文字範圍跨
unit越邊界的情況中的歧義;例如,「{The U}RL https://www.microsoft.com/ is embedded in text」中,其中「{」和「}」為文字範圍的端點。產生的範圍會移動至 DocumentRange 中,向後到達所要求
unit界限的開頭。範圍會依要求的界限數目DocumentRange往前或向後
unit移動。然後,範圍會從退化的範圍狀態通過將 End 端點移動到一個要求的
unit邊界來進行擴展。
調整範圍 透過移動與擴展調整範圍文字範圍如何調整 Move() 與 ExpandToEnclosingUnit() 的範例
Note
這些步驟是必要的,因為螢幕閱讀器通常會在插入點或任何虛擬游標位置讀出完整的單字、句子或整段。
ExpandToEnclosingUnit 尊重隱藏與可見文字。 使用者介面自動化 用戶端可以檢查 IsHiddenAttribute 以確認文字可見性。
ExpandToEnclosingUnit若給定TextUnit未被控制組支持,則 讓位給出的下一個較大TextUnit支持者。
從最小到最大單位的順序如下所示。