3

I have a RichTextbox that I would like to add button control and make it enabled for clicks.

Unfurtunatlly when you add it, it gets automatically disabled

it seems to be a FlowDocument limitation, but since this is a very simple requirement. I found hard to believe there is no clean way to enable it.

This is a solution by creating a new control extending FlowDocument but I would like to avoid it.

Description of the workaround Is there a clean way of accomplishing this?

enter image description here

<RichTextBox x:Name="txt1" HorizontalAlignment="Left" Height="183" Margin="36,10,0,0" VerticalAlignment="Top" Width="508">
    <FlowDocument IsEnabled="True">
        <Paragraph LineHeight="1">
            <Button Content="Button" Height="25" Width="93" Click="Button_Click_1"/>
        </Paragraph>
    </FlowDocument>
</RichTextBox>
RollRoll
  • 8,133
  • 20
  • 76
  • 135
  • I can't tag duplicates due to the bounty but it this seems like a good target and provides further insight into why using a RTB with FlowDocument is questionable: https://stackoverflow.com/questions/9073414/how-to-make-uielement-interactable-or-click-able-in-wpf-ui – Equalsk Dec 27 '17 at 13:46

1 Answers1

5

Just set IsDocumentEnabled property of RichTextBox to true:

<RichTextBox x:Name="txt1" IsDocumentEnabled="True" HorizontalAlignment="Left" Height="183" Margin="36,10,0,0" VerticalAlignment="Top" Width="508">
    <FlowDocument IsEnabled="True">
        <Paragraph LineHeight="1">
            <Button Content="Button" Height="25" Width="93" Click="Button_Click_1"/>
        </Paragraph>
    </FlowDocument>
</RichTextBox>
Evk
  • 98,527
  • 8
  • 141
  • 191