Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

WPF GroupBox Header Text Issue

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?

like image 629
BrianKE Avatar asked Dec 29 '25 18:12

BrianKE


2 Answers

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

like image 186
Athari Avatar answered Jan 01 '26 06:01

Athari


Header is defined more than once.

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

like image 31
Xaruth Avatar answered Jan 01 '26 08:01

Xaruth



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!