<UserControl x:Class="MaterialDesignColors.WpfExample.Grids"
             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:MaterialDesignColors.WpfExample"
             xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <ResourceDictionary Source="pack://application:,,,/MaterialDesignThemes.Wpf;component/Themes/MaterialDesignTheme.DataGrid.xaml" />
            </ResourceDictionary.MergedDictionaries>
        </ResourceDictionary>
    </UserControl.Resources>
    <ScrollViewer>
        <StackPanel>
            <TextBlock>Custom Columns</TextBlock>
            <DataGrid Margin="0 8 0 0" ItemsSource="{Binding Items3}" CanUserSortColumns="True" CanUserAddRows="False" AutoGenerateColumns="False">
                <DataGrid.Columns>
                    <DataGridCheckBoxColumn Binding="{Binding IsSelected}" 
                                                ElementStyle="{StaticResource MaterialDesignDataGridCheckBoxColumnStyle}"
                                                EditingElementStyle="{StaticResource MaterialDesignDataGridCheckBoxColumnEditingStyle}">
                        <DataGridCheckBoxColumn.Header>
                            <!--padding to allow hit test to pass thru for sorting -->
                            <Border Background="Transparent" Padding="6 0 6 0" HorizontalAlignment="Center">
                                <CheckBox HorizontalAlignment="Center"                                               
                                              DataContext="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGrid}}, Path=DataContext}"
                                              IsChecked="{Binding IsAllItems3Selected}" />
                            </Border>
                        </DataGridCheckBoxColumn.Header>
                    </DataGridCheckBoxColumn>
                    <DataGridTextColumn Binding="{Binding Code}"
                                            Header="Code"
                                            EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnEditingStyle}"
                                            />
                    <!-- if you want to use the pop up style (MaterialDesignDataGridTextColumnPopupEditingStyle), you must use MaterialDataGridTextColumn -->
                    <wpf:MaterialDataGridTextColumn Binding="{Binding Name}"
                                                        Header="Name"                                                        
                                                        EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}" 
                                                        />
                    <!-- set a max length to get an indicator in the editor -->
                    <wpf:MaterialDataGridTextColumn Binding="{Binding Description}"
                                                        Header="Description"                                                        
                                                        MaxLength="255" 
                                                        EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}" 
                                                        />
                    <wpf:MaterialDataGridTextColumn Binding="{Binding Numeric}"
                                                        Header="Numeric"                                                         
                                                        EditingElementStyle="{StaticResource MaterialDesignDataGridTextColumnPopupEditingStyle}">
                        <DataGridTextColumn.HeaderStyle>
                            <Style TargetType="{x:Type DataGridColumnHeader}" BasedOn="{StaticResource MaterialDesignDataGridColumnHeader}">
                                <Setter Property="HorizontalAlignment" Value="Right" />
                            </Style>
                        </DataGridTextColumn.HeaderStyle>
                        <DataGridTextColumn.ElementStyle>
                            <Style TargetType="{x:Type TextBlock}">
                                <Setter Property="HorizontalAlignment" Value="Right" />
                            </Style>
                        </DataGridTextColumn.ElementStyle>
                    </wpf:MaterialDataGridTextColumn>

                    <!-- use custom combo box column to get better combos. Use ItemsSourceBinding as your binding template to be applied to each combo -->
                    <wpf:MaterialDataGridComboBoxColumn Header="Food"        
                                                            SelectedValueBinding="{Binding Food}"                                                            
                                                            ItemsSourceBinding="{Binding RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type DataGrid}}, Path=DataContext.Foods}" />
                </DataGrid.Columns>
            </DataGrid>
            <TextBlock Margin="0 24 0 0">Auto Generated Columns</TextBlock>
            <DataGrid  Margin="0 8 0 0" ItemsSource="{Binding Items3}" CanUserSortColumns="True" CanUserAddRows="False" />
        </StackPanel>
    </ScrollViewer>
</UserControl>
