3

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?

BrianKE
  • 4,035
  • 13
  • 65
  • 115
  • My original post had a copy error and showed Header as being defined twice. In my code it is not defined twice and still shows "System.Windows.Controls.Texblock". It compiles fine and runs showing "System.Windows.Controls.Texblock". – BrianKE Aug 19 '14 at 12:24
  • 1
    Do you change template for `GroupBox`? If yes, and it seems so, post you template – dkozl Aug 19 '14 at 12:27
  • Error is not in this code (see my answer), so it's from elsewhere (template I think) – Xaruth Aug 19 '14 at 12:28

2 Answers2

5

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

Athari
  • 33,702
  • 16
  • 105
  • 146
1

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.

Victor2748
  • 4,149
  • 13
  • 52
  • 89
Xaruth
  • 4,034
  • 3
  • 19
  • 26
  • It's a typo in the question. WPF won't compile XAML with duplicate properties, IIRC, so your correction achieves nothing. – Athari Aug 19 '14 at 12:21
  • The duplicate header was a typo int he original post. I have updated the post with correct XAML. – BrianKE Aug 19 '14 at 12:25
  • OK, so error comes from elsewhere, not from this corrected code. – Xaruth Aug 19 '14 at 12:25
  • In a simple example, just with that code, header is in bold like you want. Please give us more details ! – Xaruth Aug 19 '14 at 12:26