带有内联样式的复选框文本

发布于 2024-12-21 07:51:45 字数 654 浏览 5 评论 0原文

我正在尝试在包含 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 的 Text 属性将会更改(即 textBlock.Text == "unstyledText YellowBoldText unstyledText" 返回 true),但 CheckBox 中的文本在视觉上不会发生变化。

是否有办法让 CheckBox 内的 TextBlock 的行为与其他 TextBlock 的行为相同?

I am trying to style text on a page that contains TextBlocks and TextBlocks as the content of CheckBoxes

I want to do something like this (where textBlock is the TextBlock contained within the CheckBox - or anything that inherits from 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");

This works on the TextBlocks that are not inside a CheckBox. If they are inside a CheckBox, the TextBlock's Text property will change (ie. textBlock.Text == "unstyledText yellowBoldText unstyledText" returns true), but the text in the CheckBox will not visually change.

Is there anyway to get the TextBlocks inside a CheckBox to behave the same way as the other TextBlocks?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

记忆之渊 2024-12-28 07:51:45

CheckBox 的样式必须覆盖 TextBlock 在其状态中的样式。

不要使用带有 RunTextBlock 作为 CheckBox 的内容,而是尝试添加带有 StackPanel 的水平 StackPanel代码>文本块。

如果布局未按您预期的方式呈现(例如 WordWrap),请尝试编辑 ComboBox 的样式。

The CheckBox's style must be overriding the TextBlock's style in its States.

Instead of having a TextBlock with Runs as a content of your CheckBox, try adding a horizontal StackPanel with TextBlocks.

If the layout is not rendered as you would expect (for example WordWrap) try editing the style of the ComboBox.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文