我有一个 RichTextbox,我想添加按钮控件并使其启用点击。
不幸的是,当您添加它时,它会自动禁用
这似乎是 FlowDocument 的限制,但因为这是一个非常简单的要求。我发现很难相信没有干净的方法来启用它。
这是通过创建一个扩展 FlowDocument 的新控件的解决方案,但我想避免它。
Description of the workaround 是否有一种简洁的方法来完成此操作?
<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>
最佳答案
只需将 RichTextBox
的 IsDocumentEnabled
属性设置为 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/