1

我正在尝试在包含 TextBlocks 和 TextBlocks 作为 CheckBoxes 内容的页面上设置文本样式

我想做这样的事情(其中 textBlock 是 CheckBox 中包含的 TextBlock - 或从 System.Windows.Controls.Control 继承的任何内容)

textBlock.Inlines.Add("unstyledText");
textBlock.Inlines.Add(new Run { Text = "yellowBoldText ", Foreground = new SolidColorBrush(Colors.Yellow), FontWeight = FontWeights.Bold });
textBlock.Inlines.Add("unstyledText");

这适用于不在 CheckBox 内的 TextBlock。如果它们在 CheckBox 内,则 TextBlock 的 Text 属性将发生变化(即textBlock.Text == "unstyledText yellowBoldText unstyledText"返回 true),但 CheckBox 中的文本不会在视觉上发生变化。

有没有办法让 CheckBox 中的 TextBlocks 与其他 TextBlocks 的行为方式相同?

4

1 回答 1

0

CheckBox' 样式必须在其州中覆盖'TextBlock样式。

尝试添加一个带s的水平线,而不是TextBlock使用Runs 的内容。CheckBoxStackPanelTextBlock

如果布局未按预期呈现(例如 WordWrap),请尝试编辑ComboBox.

于 2011-12-15T17:28:54.770 回答