Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable button added to Richtextbox without creating a new class overriding IsEnabledCore?

Tags:

c#

wpf

xaml

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>
like image 574
RollRoll Avatar asked Sep 03 '25 04:09

RollRoll


1 Answers

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>
like image 50
Evk Avatar answered Sep 06 '25 07:09

Evk