<UserControl x:Class="C1ExpressionEditorSample.DataGridGrouping"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:C1ExpressionEditorSample"
             mc:Ignorable="d" 
             d:DesignHeight="500" d:DesignWidth="800">
    <UserControl.Resources>
        <Style x:Key="GroupHeaderStyle" TargetType="{x:Type GroupItem}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type GroupItem}">
                        <Expander IsExpanded="True" Background="White" Foreground="Black">
                            <Expander.Header>
                                <DockPanel>
                                    <TextBlock Text="{Binding Name}" />
                                    <TextBlock FontWeight="Bold" Text=" ("/>
                                    <TextBlock FontWeight="Bold" Text="{Binding ItemCount}"/>
                                    <TextBlock FontWeight="Bold" Text=" Items)"/>
                                </DockPanel>
                            </Expander.Header>
                            <ItemsPresenter />
                        </Expander>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Resources>
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="Auto"/>
            <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <local:ExpressionEditorEE x:Name="editor" OKContent="Add expression to DataGrid groups." CancelContent="Clear all groups"/>
        <DataGrid x:Name="grid" Grid.Column="1" Grid.RowSpan="2">
            <DataGrid.GroupStyle>
                <GroupStyle ContainerStyle="{StaticResource GroupHeaderStyle}">
                    <GroupStyle.Panel>
                        <ItemsPanelTemplate>
                            <DataGridRowsPresenter />
                        </ItemsPanelTemplate>
                    </GroupStyle.Panel>
                </GroupStyle>
            </DataGrid.GroupStyle>
        </DataGrid>
    </Grid>
</UserControl>
