<Window x:Class="Grouping_Sample.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        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"
        xmlns:local="clr-namespace:Grouping_Sample"
        mc:Ignorable="d"
        Title="Grouping_Sample" Height="350" Width="300">
    <Window.Resources>
        <local:GroupingConverter x:Key="conv" />
        <CollectionViewSource x:Key="groupView">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="CategoryID" Converter="{StaticResource conv}" />
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>
    </Window.Resources>
    <Grid>
        <ListBox DisplayMemberPath="ProductName" Margin="6" ItemsSource="{Binding Source={StaticResource groupView}}" >
            <ListBox.GroupStyle>
                <GroupStyle>
                    <GroupStyle.HeaderTemplate>
                        <DataTemplate>
                            <TextBlock Text="{Binding Name}" FontWeight="Bold" Background="DarkGray" Padding="5"/>
                        </DataTemplate>
                    </GroupStyle.HeaderTemplate>
                </GroupStyle>
            </ListBox.GroupStyle>
        </ListBox>
    </Grid>
</Window>


