I am trying to select text in my FlowDocumentScrollViewer.
I am able to find the TextPointer start position and end position. So I have 2 TextPointers...
TextPointer startPos;
TextPointer endPos;
Using these 2 TextPointers I am trying to select text in my FlowDocumentScrollViewer. I am doing it like this...
flowDocumentScrollViewer.Selection.Select(startPos, endPos);
I would expect this to highlight the selected text. But it is not doing this.
Why is this not working???
[UPDATE] This is how I am getting the TextPointers:
TextPointer pointer = flowDocument.Document.ContentStart;
while (pointer != null)
{
if (pointer.GetPointerContext(LogicalDirection.Forward) == TextPointerContext.Text)
{
string textRun = pointer.GetTextInRun(LogicalDirection.Forward);
// where textRun is the text in the flowDocument
// and searchText is the text that is being searched for
int indexInRun = textRun.IndexOf(searchText);
if (indexInRun >= 0)
{
TextPointer startPos = pointer.GetPositionAtOffset(indexInRun);
TextPointer endPos = pointer.GetPositionAtOffset(indexInRun + searchText.Length);
}
}
pointer = pointer.GetNextContextPosition(LogicalDirection.Forward);
}