views:

19

answers:

1

When I set different font to Group box the child controls also set to the font of group box.

I have to set each child control with different font property.

Like I have to set child control Font property to

<GroupBox Font Size = "14"> <Label FontWeight"Normal" ,Font Size ="8"/> <TextBox FontWeight"Normal" ,Font Size ="8"/>  </GroupBox>

Is this the best aprroach to set the font property of each and every child inside the group box?

Please suggest!!

+1  A: 

If you want labels within the GroupBox to be a smaller size and everything else in the group box to match the GroupBox header text size, use a style:

<GroupBox FontSize="14" Header="Header Text">
  <GroupBox.Resources>
    <Style TargetType="Label">
      <Setter Property="FontSize" Value="8" />
      <Setter Property="FontWeight" Value="Normal" />
    </Style>
  </GroupBox.Resources>

  <StackPanel>
    <Label Text="Label Text" />
    <Label Text="Another Label" />
    <TextBlock Text="This will match the group header" />
  </StackPanel>
</GroupBox>

If you want the GroupBox header to be different from all the text in the GroupBox, use a TextBlock for a header instead of a string:

<GroupBox>
  <GroupBox.Header>
    <TextBlock Text="Header Text" FontSize="14" />
  </GroupBox.Header>

  <StackPanel>
    <Label Text="Label Text" />
    <Label Text="Another Label" />
    <TextBlock Text="This will be the default font" />
  </StackPanel>

</GroupBox>

These two techniques can be combined to have one size for the GroupBox header, another size for labels, and a third (default) size for all other text in the GroupBox.

Ray Burns