C# – WPF GroupBox Header Text Issue

cgroupboxwpfxaml

I have the following XAML which displays correctly:

    <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".

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

Best Answer

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

Related Topic