我有一个 RichTextBox,我在代码中添加了一个按钮...我可以设置按钮的前景,但不能设置背景。
Button b = new()
{ // Unspecified width and button fills width
Content = "Test",
FontSize = 20,
FontWeight = FontWeights.Bold,
Foreground = Brushes.Black,
Background = Brushes.Green,
IsEnabled = true
};
// Add button to block, then insert before current block
BlockUIContainer blockUIContainer = new(b);
Script.Document.Blocks.InsertBefore(block, blockUIContainer);
重点! RichTextBox 集
IsDocumentEnabled="True"
一旦 IsDocumentEnabled 设置为 true,添加的按钮就会正常响应(事件现在可以工作)。即使 RichTextBox 有
IsReadOnly="False"