Click here to Skip to main content
15,892,005 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hi
When I run the following code, I don't get any text in the group header.

The data behind is a datatable, and all the records show up in the listbox according to the specification in the datatemplate (itemTemplate), but when I try to create the header in the same way as I do the binding in the datatemplate for the itemTemplate I only get the color styling right.

Why don't I get any text in my group header?

Code:

XML
<Window.Resources>
    <src:KontaktListe x:Key="cList" />
</Window.Resources>
<Grid>
    <Grid.Resources>
        <CollectionViewSource Source="{StaticResource cList}" x:Key="cvs">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="City"/>
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>
        <DataTemplate x:Key="categoryTemplate">
            <TextBlock Text="{Binding Path=City}" FontWeight="Bold"
                       Background="Beige" Margin="0,0,0,0"
                       Foreground="Black"/>
        </DataTemplate>
        <DataTemplate x:Key="itemTemplate">
            <Grid Margin="4">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="50" />
                    <ColumnDefinition Width="100" />
                    <ColumnDefinition Width="50" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>
                <TextBlock Text="{Binding Path=FirstName}"  Grid.Column="0" />
                <TextBlock Text="{Binding Path=LastName}"  Grid.Column="1" />
                <TextBlock Text="{Binding Path=ZipCode}" FontWeight="Bold" Grid.Column="2" />
                <TextBlock Text="{Binding Path=City}" Grid.Column="3" />
            </Grid>
        </DataTemplate>
    </Grid.Resources>
    <ListBox Name="MyContacts"
             ItemTemplate="{StaticResource itemTemplate}"
             ItemsSource="{Binding Source={StaticResource cvs}}">
        <ListBox.GroupStyle>
            <GroupStyle HeaderTemplate="{StaticResource categoryTemplate}" />
        </ListBox.GroupStyle>
    </ListBox>
</Grid>



/Stig
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900