WPF GroupBox 标题文本问题

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25383145/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-13 12:22:28  来源:igfitidea点击:

WPF GroupBox Header Text Issue

c#wpfxamlgroupbox

提问by BrianKE

I have the following XAML which displays correctly:

我有以下正确显示的 XAML:

    <GroupBox Name="RulesGroupBox" Header="Rules">

        <StackPanel Name="RulesStackPanel"
                HorizontalAlignment="Left">

....

        </StackPanel>
    </GroupBox>

I now want to make the header text bold using the following (which I know works in other projects):

我现在想使用以下内容(我知道在其他项目中有效)使标题文本变为粗体:

    <GroupBox Name="RulesGroupBox">
        <GroupBox.Header>
            <TextBlock FontWeight="Bold" Text="Rules"></TextBlock>
        </GroupBox.Header>

        <StackPanel Name="RulesStackPanel"
                HorizontalAlignment="Left">
....

        </StackPanel>
    </GroupBox>

For some reason, in this project, this change has the effect of making the text displayed for the Header text "System.Windows.Controls.TextBlock" and not "Rules". The text is now bold but not displaying "Rules".

出于某种原因,在此项目中,此更改具有使标题文本“System.Windows.Controls.TextBlock”而非“规则”的文本显示的效果。文本现在是粗体,但不显示“规则”。

Any idea why the chagne would not show "Rules" in bold?

知道为什么 chagne 不会以粗体显示“规则”吗?

采纳答案by Athari

You likely have changed GroupBox's HeaderTemplateand this template supports displaying only text.

您可能已更改GroupBox'sHeaderTemplate并且此模板仅支持显示文本。

回答by Xaruth

Headeris defined more than once.

Header被定义不止一次。

<GroupBox Name="RulesGroupBox">
    <GroupBox.Header>
        <TextBlock FontWeight="Bold" Text="Rules"></TextBlock>
    </GroupBox.Header>

    <StackPanel Name="RulesStackPanel"
            HorizontalAlignment="Left">
....

    </StackPanel>
</GroupBox>

"Rules" appears in bold with this correction.

此次更正后,“规则”以粗体显示。

Edit :This answer was made for the question before it has been edited. It's clearly not the good answer for the edited question.

编辑:此答案是在编辑之前针对该问题进行的。这显然不是编辑问题的好答案。