1

enter image description here

<RichTextBox Name="rtb" Margin="20">
    <FlowDocument>
        <Paragraph>Today is the day before tomorrow. Today is the day before tomorrow. Today is the day before tomorrow. Today is the day before tomorrow. Today is the day before tomorrow. Today is the day before tomorrow. Today is the day before tomorrow.</Paragraph>
        <Table CellSpacing="10"
               Padding="0"
               Background="Yellow"
               FontFamily="Arial"
               FontSize="12">
            <Table.Columns>
                <TableColumn Width="70" />
                <TableColumn Width="120" />
                <TableColumn Width="200" />
            </Table.Columns>
            <TableRowGroup Background="Gold">
                <TableRow>
                    <TableCell ColumnSpan="3">
                        <Paragraph Foreground="Gold" Background="Black" TextAlignment="Center" FontSize="16">Table Header</Paragraph>
                    </TableCell>
                </TableRow>
                <TableRow>
                    <TableCell BorderThickness="1" BorderBrush="Black">
                        <Paragraph>Cell 0,0</Paragraph>
                    </TableCell>
                    <TableCell BorderThickness="1" BorderBrush="Black">
                        <Paragraph>Cell 0,1</Paragraph>
                    </TableCell>
                    <TableCell BorderThickness="1" BorderBrush="Black">
                        <Paragraph>Cell 0,2</Paragraph>
                    </TableCell>
                </TableRow>
                <TableRow>
                    <TableCell BorderThickness="1" BorderBrush="Black">
                        <Paragraph>Cell 1,0</Paragraph>
                    </TableCell>
                    <TableCell BorderThickness="1" BorderBrush="Black">
                        <Paragraph>Cell 1,1</Paragraph>
                    </TableCell>
                    <TableCell BorderThickness="1" BorderBrush="Black">
                        <Paragraph>Cell 1,2</Paragraph>
                    </TableCell>
                </TableRow>
            </TableRowGroup>
        </Table>
        <Paragraph>Today is the day before tomorrow. Today is the day before tomorrow. Today is the day before tomorrow. Today is the day before tomorrow. Today is the day before tomorrow. Today is the day before tomorrow. Today is the day before tomorrow.</Paragraph>
    </FlowDocument>
</RichTextBox>

For FindAgain I need the TextRange from selection end till the end of the document:

string rangeText = new TextRange(rtb.Selection.End, rtb.Document.ContentEnd).Text;

I expected rangeText to start with " 1,1", but it starts with "Cell 1,0". Seems weird to me, however, how can I get the desired range?

Pollitzer
  • 1,580
  • 3
  • 18
  • 28
  • 1
    This seems relevant https://social.msdn.microsoft.com/Forums/vstudio/en-US/fc46affc-9dc9-4a8f-b845-89a024b263bc/how-to-find-and-replace-words-in-wpf-richtextbox?forum=wpf have you read it? – BugFinder Mar 01 '16 at 16:09
  • This behavior is perfectly consistent with the behavior you can observe in Microsoft Word for example. Try pasting this `FlowDocument` into Microsoft Word and try making that selection from `"1,1"` to the end of the document. The whole row becomes selected when the selection leaves the row. – Szabolcs Dézsi Mar 01 '16 at 19:54
  • @BugFinder: The linked site shows a method to get the next occurrence of a keyword. Since I can start searching at any given position in the document, I think it's a workable solution for FindAgain, also inside `Table`s. @Szabolcs Dézsi: I have no problem with this behavior concerning selections made by the user. Nevertheless I think it should be possible to get a `TextRange` from the middle of a `Table` to the end of the document. @wogsland: Why is `Table` a bad tag? – Pollitzer Mar 02 '16 at 08:28

0 Answers0