I am trying to select the text in my FlowDocumentScrollViewer.
I am able to find the position of the text point start position and the end. So I have 2 textpointers ...
Textpoint startups; Text pointer and piece; Using these 2 text pointers I am trying to select text in my documentary document. I am doing this like this ...
flowDocumentScrollViewer.Selection.Select (startPos, endPos); I hope that this highlighted the selected text. But it is not doing this.
Why this is not working ???
[UPDATE] How do I achieve textpointer?
Text pointer pointer = flow document. Document. Contact Start; While (indicator! = Zero) {if (indicator gatepointctostesx (logical direction.ford) == textpointcontact.txt) {string textRun = pointer.GetTextInRun (logical direction. Forward); // where there is text in textRun flowDocument // and the search text is the text that is being searched for int indexInRun = textRun.IndexOf (searchText); If (indexInRun> = 0) {TextPointer startPos = pointer.GetPositionAtOffset (indexInRun); Textpoint and Piece = Pointer Getpazy's offset (indexError + search text lang); }} Pointer = Pointer Get Next Contact Position (Logical Direction. Ford); } I have copied the following code from the MSDN documentation of the method, to the rich textbox. Has changed with a FlowDocumentScrollViewer and it works as expected How did you define your TextPointers? It seems that causes your problem to be the most probable cause. Update: I have updated my code to include your selection algorithm and it still works. The only thing that knows how to isolate me is "break" after selection, otherwise it will choose from the beginning of the first incident of search till the end of the last event. Apart from this, I could have thought that your search text may not be included in your document at all (possibly a cover problem?), But it is just guessing. Did you debug your code? Are textpointers valid when trying to select text (no zero etc)?
XAM:
& lt; Flow Document Strap Controller GotMouseCapture = "richTB_GotMouseCapture" name = "richTB" & gt; & Lt; FlowDocument & gt; & Lt; Paragraph name = "my paragraph" & gt; & Lt; Run & gt; When the user clicks on RichTextBox, the selected text changes to the program. & Lt; / Run & gt; & Lt; / Paragraph & gt; & Lt; / FlowDocument & gt; & Lt; / FlowDocumentScrollViewer & gt;
Code:
Private Zero Rich TTB_GotMusicArt (Object Sender, MouseInventErgus E) {string searchText = "text"; Text Pointer Pointer = richTB.Document.ContentStart; While (indicator! = Zero) {if (indicator gatepointctostesx (logical direction.ford) == textpointintext.text) {string textRun = pointer.GetTextInRun (logical direction. Forward); // where there is text in textRun flowDocument // and the search text is the text that is being searched for int indexInRun = textRun.IndexOf (searchText); If (indexInRun> = 0) {TextPointer startPos = pointer.GetPositionAtOffset (indexInRun); Textpoint and Piece = Pointer Getpossyet offset (indexError + search .text); RichTB.Selection.Select (startPos, endPos); break; }} Pointer = Pointer Get Next Contact Position (Logical Direction. Ford); }}
Comments
Post a Comment