0

Ia have RichTextBox with content defined as following:

                    <FlowDocument>
                    <Paragraph x:Name="para">
                        <Label Padding="0,0,0,0" Margin="0,0,0,0">
                            <Hyperlink Click="Hyperlink_Click">
                                <Run Text="{Binding Txt}" x:Name="rxm" />
                            </Hyperlink>
                        </Label>
                        <Label Padding="0,0,0,0" Margin="0,0,0,0" FontWeight="Bold" Content=" - " />
                        <Label Padding="0,0,0,0" Margin="0,0,0,0" FontWeight="Bold" x:Name="name" Content="Some name"
                   ToolTipService.ShowDuration="10000">
                            <Label.ToolTip>
                                <ContentControl Content="Tooltip" />
                            </Label.ToolTip>
                        </Label>
                    </Paragraph>
                </FlowDocument>

The problem is that I'm not able to get selected text properly. I'm getting few whitespaces instead. So i tried to retrieve all FlowDocument's text at least with following piece of code:

            TextRange tr = new TextRange(
          doc.Selection.Start,
          doc.Selection.End);
        MemoryStream ms = new MemoryStream();
        tr.Save(ms, DataFormats.Xaml);
        string xamlString =
           ASCIIEncoding.Default.GetString(ms.ToArray());

It turned out, that I'm getting just few runs with blank space in each of them:

<Section xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" ...  <Paragraph>
    <Run> </Run>
    <Run> </Run>
    <Run> </Run>
    <Run> </Run>
    <Run> </Run>
</Paragraph>

Looks like the "document" view is completely different from visual view although i have no idea why these Runs are empty. Does anybody know how to get the selected text (even without any formatting) properly? Any help appreciated

grzegorz_p
  • 483
  • 1
  • 4
  • 14

1 Answers1

0

I found a suitable solution:

How can I copy WPF FlowDocument InlineUIContainer contents?

Determining the selected InlineUIContainer in a WPF RichTextBox

It'd be quite a lot of coding to handle every possible FlowDocument content but i'm happy with it for now

Community
  • 1
  • 1
grzegorz_p
  • 483
  • 1
  • 4
  • 14