Silverlight DataGrid group header style sample (CSSL4DataGridGroupHeaderStyle)

This project illustrates how to define group header style of different levels and define group header style according to group header content.

C# (48.5 KB)
 
 
 
 
 
4 Star
(1)
13,944 times
Add to favorites
5/5/2011
E-mail Twitter del.icio.us Digg Facebook
<UserControl xmlns:datagrid="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  x:Class="CSSL4DataGridGroupHeaderStyle.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:local="clr-namespace:CSSL4DataGridGroupHeaderStyle"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             
    mc:Ignorable="d"
    d:DesignHeight="300" d:DesignWidth="400">
    <UserControl.Resources>
        <local:ColorConverter x:Key="ColorConverter" />
    </UserControl.Resources>

    <Grid x:Name="LayoutRoot">
        <ScrollViewer>
            <datagrid:DataGrid x:Name="PeopleList">
                <datagrid:DataGrid.RowGroupHeaderStyles>
                    <!-- Style for groups at top level -->
                    <Style TargetType="datagrid:DataGridRowGroupHeader">
                        <Setter Property="Template">
                            <Setter.Value>
                                <ControlTemplate TargetType="datagrid:DataGridRowGroupHeader">
                                    <StackPanel  HorizontalAlignment="Left" Width="330" Background="{Binding Name, Converter={StaticResource ColorConverter}}" >
                                        <TextBlock Text="{Binding Name}"/>
                                    </StackPanel>
                                </ControlTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
                    <!-- Style for the second groups level -->
                    <Style TargetType="datagrid:DataGridRowGroupHeader">
                        <Setter Property="Background" Value="LightBlue" />
                    </Style>
                </datagrid:DataGrid.RowGroupHeaderStyles>
            </datagrid:DataGrid>
        </ScrollViewer>
    </Grid>
</UserControl>