WPF [SOLVED]: How to enable button added to Richtextbox without creating a new class overriding IsEnabledCore?

WPF [SOLVED]: How to enable button added to Richtextbox without creating a new class overriding IsEnabledCore?

Home Forums Frameworks WPF WPF [SOLVED]: How to enable button added to Richtextbox without creating a new class overriding IsEnabledCore?

Tagged: , ,

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #246848

    Cloudy Point
    Keymaster

    QuestionQuestion

    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>
    

    #246849

    Cloudy Point
    Keymaster

    Accepted AnswerAnswer

    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>
    

    Source: https://stackoverflow.com/questions/47935661/how-to-enable-button-added-to-richtextbox-without-creating-a-new-class-overridin
    Author: Evk
    Creative Commons License
    This work is licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 4.0 International License.

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.