TextBlock not honouring the colour of the preset styles when used within a ListBox's ControlTemplate of a GroupStyle.Container style

Apr 1, 2013 at 4:52 PM
Edited Apr 1, 2013 at 5:03 PM
I have a grouped listbox where I am trying to set the appearance of each group. I have set the proper style on the textblock in question (see xaml where I put <!-- LOOK HERE -->), and everything but the proper color is set for the textblock.

I can switch betweem Normal, Header1, Emphasis, Small etc. and it changes the proper font/size.. but it never sets the proper colour. It is always black, which is the proper color for the Light theme, but not for the Dark theme.
 <ListBox Grid.Row="1"
                 ItemsSource="{Binding Projects}"
                 ItemTemplate="{StaticResource ProjectTemplate}"
                 SelectedItem="{Binding SelectedProject, Mode=TwoWay}"

                        <Style TargetType="{x:Type GroupItem}">
                            <Setter Property="Template">
                                    <ControlTemplate TargetType="{x:Type GroupItem}">
                                                <RowDefinition Height="Auto" />
                                                <RowDefinition Height="Auto" />

                                                    <ColumnDefinition Width="Auto" />
                                                    <ColumnDefinition Width="*" />

                                                <Button x:Name="expandCollapseBtn"
                                                        Command="{Binding Path=Items[0].ExpandCollapseCommand}"

                                                        <Style TargetType="{x:Type Button}">
                                                                <DataTrigger Binding="{Binding ItemCount}"
                                                                    <Setter Property="Visibility"
                                                                            Value="Hidden" />

                                                            <Border HorizontalAlignment="Center"
                                                                <Image x:Name="exImage"
                                                                       Source="{Binding Path=Items[0].ExpandButtonImage}"
                                                                        <DropShadowBitmapEffect />
                                                        <ToolTip Content="{Binding ExpandButtonToolTip}" />



                                               <TextBlock Grid.Column="1"
                                                           Style="{StaticResource Heading2}"
                                                           Text="{Binding Path=Name}">                                                   
<!-- END LOOK HERE -->

                                            <Grid Grid.Row="1"
                                                  Visibility="{Binding Path=Items[0].IsExpanded, Converter={StaticResource boolToVis}}">
                                                <ItemsPresenter />
Apr 1, 2013 at 4:59 PM
The TextBlock styles Normal, Header1, Emphasis, Small etc. do not include a Foreground brush. Their values are inherited.

What if you explicitly derive from the default ListBox style by specifiying the BasedOn like so:
<Style BasedOn="{StaticResource {x:Type ListBox}}" >
Apr 1, 2013 at 5:12 PM
I am not sure how to apply this. It appears that the listbox is getting the style, but it is not being applied to the group style.
Apr 1, 2013 at 6:05 PM
The default ListBox style specifies an ItemContainerStyle that does use the correct foreground brush. Adding the BasedOn attribute to your custom ListBox style explicitly states that the default style should be used as base.
Apr 2, 2013 at 2:29 AM
Edited Apr 2, 2013 at 2:29 AM
Yes I understand inheriting a style, but in this case I am not modifying the ItemContainerStyle, but rather the GroupStyle. I am not certian how to apply a style to the listbox's GroupStyle which is based on an inherited StaticResource.

Because the listbox is already showing that it is displaying the proper style, I would have thought that the TextBlock's foreground brushes would be carried into the GroupStyle..but this is not the case.
Apr 2, 2013 at 6:35 AM
The default mui ListBox style does not define a GroupStyle. It's my guess a default GroupStyle is used with a Foreground set to black. You may want to add the following Foreground Setter to the GroupStyle.ContainerStyle:
<Setter Property="Foreground" Value="{DynamicResource ItemText}" />
Apr 2, 2013 at 2:07 PM
Thanks kozw - that solved my problem!