WPF GroupBox Header Text Issue

11,176

Solution 1

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

Solution 2

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.

Share:
11,176
BrianKE
Author by

BrianKE

Updated on June 04, 2022

Comments

  • BrianKE
    BrianKE almost 2 years

    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?

  • Athari
    Athari almost 10 years
    It's a typo in the question. WPF won't compile XAML with duplicate properties, IIRC, so your correction achieves nothing.
  • BrianKE
    BrianKE almost 10 years
    The duplicate header was a typo int he original post. I have updated the post with correct XAML.
  • Xaruth
    Xaruth almost 10 years
    OK, so error comes from elsewhere, not from this corrected code.
  • Xaruth
    Xaruth almost 10 years
    In a simple example, just with that code, header is in bold like you want. Please give us more details !
  • BrianKE
    BrianKE almost 10 years
    Thank you. It was being defined in a global dictionary that I was not aware of.