c# - 如何在不创建覆盖 IsEnabledCore 的新类的情况下启用添加到 Richtextbox 的按钮?

标签 c# wpf xaml

我有一个 RichTextbox,我想添加按钮控件并使其启用点击。

不幸的是,当您添加它时,它会自动禁用

这似乎是 FlowDocument 的限制,但因为这是一个非常简单的要求。我发现很难相信没有干净的方法来启用它。

这是通过创建一个扩展 FlowDocument 的新控件的解决方案,但我想避免它。

Description of the workaround 是否有一种简洁的方法来完成此操作?

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>

最佳答案

只需将 RichTextBoxIsDocumentEnabled 属性设置为 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>

关于c# - 如何在不创建覆盖 IsEnabledCore 的新类的情况下启用添加到 Richtextbox 的按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47935661/

相关文章:

c# - 在 rdlc 报告中动态隐藏列

c# - 使用 mvvm 和 wpf 重用菜单

wpf - 是否可以在 WPF TabControl 中左对齐标题?

xaml - Viewcell XAML + CS 抛出“不支持构建操作 'Page'”错误

c# - 带有提醒场景的 Toast 通知未停留在屏幕上

c# - 如何在 WPF 中操作另一个类的窗口对象

c# - 如何使表达式将值类型视为引用类型?

wpf - 将焦点设置到 WPF 中用户控件内的控件时未在 IDE 中显示 View

c# - 如何在模型中直接使用数据注释

wpf - XAML 命名空间命名约定