在我的 System.Windows.Controls.RichTextBox 中,我想找到给定单词的 TextRange。但是,在第一个找到的单词之后,它并没有给我正确的 PositionAtOffset。第一个是正确的,然后对于下一个找到的单词,位置不正确。我是否使用了正确的方法?
循环遍历 listOfWords
Word= listOfWords[j].ToString();
startPos = new TextRange(transcriberArea.Document.ContentStart, transcriberArea.Document.ContentEnd).Text.IndexOf(Word.Trim());
leftPointer = textPointer.GetPositionAtOffset(startPos + 1, LogicalDirection.Forward);
rightPointer = textPointer.GetPositionAtOffset((startPos + 1 + Word.Length), LogicalDirection.Backward);
TextRange myRange= new TextRange(leftPointer, rightPointer);