<!--http://w...content-available-to-author-only...x.com-->
<Window x:Class="WPF_CRUD_EFCodeFirst_Simple.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Wpf Example: CRUD EF Code First " Height="350
        " Width="600">

    <Grid>
        <!--Chia Form thành 4 hàng-->
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>
        <!--Hàng 1-->
        <Label Grid.Row="0" Content="DEMO" FontWeight="Bold" HorizontalAlignment="Center"/>

        <!--Hàng 2-->
        <Grid Grid.Row="1">
            <!--Chia thành 2 hàng và 4 cột nhỏ-->
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
                <RowDefinition Height="Auto"/>
            </Grid.RowDefinitions>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
                <ColumnDefinition Width="Auto"/>
                <ColumnDefinition Width="*"/>
            </Grid.ColumnDefinitions>
            <Label Grid.Row="0" Grid.Column="0" Content="Employee Id:"/>
            <Label Grid.Row="1" Grid.Column="0" Content="First Name:"/>
            <Label Grid.Row="1" Grid.Column="2" Content="Last Name:"/>
            <Label Grid.Row="2" Grid.Column="0" Content="Birthday:"/>
            <Label Grid.Row="2" Grid.Column="2" Content="Dep Id:"/>

            <TextBox Name="TxtId" Grid.Row="0" Grid.Column="1" IsEnabled="False" Margin="5,5,5,5"
                     Text="{Binding DataContext.CurrentSelectedEmployee.Id}" />
            <TextBox Name="TxtFirstName" Grid.Row="1" Grid.Column="1"  Margin="5,5,5,5"
                     Text="{Binding DataContext.CurrentSelectedEmployee.FirstName}" />
            <TextBox Name="TxtLastName" Grid.Row="1" Grid.Column="3"  Margin="5,5,5,5" 
                     Text="{Binding DataContext.CurrentSelectedEmployee.LastName}" />

            <DatePicker Name="DtpkBirthday" Grid.Row="2" Grid.Column="1"  Margin="5,5,5,5"
                     SelectedDate="{Binding DataContext.CurrentSelectedEmployee.Birthday}" />

            <ComboBox Name="CbbDepartment" Grid.Row="2" Grid.Column="3"  Margin="5,5,5,5" 
                      ItemsSource="{Binding DataContext.Departmentses}"
                      SelectedValuePath="Id"
                      DisplayMemberPath="Name"
                      SelectedValue="{Binding DataContext.CurrentSelectedEmployee.DepId}" />
        </Grid>

        <!--Hàng 3-->
        <StackPanel Grid.Row="2" Orientation="Horizontal" Margin="0,10,0,10" HorizontalAlignment="Center">
            <Button Name="BtnInsert" Foreground="Teal" Content="&#xf0fe;" Width="70" Height="35" Margin="0,0,40,0" Background="Transparent" BorderThickness="0" FontSize="30" Style="{StaticResource FontAwesome}" Click="BtnInsert_Click"/>
            <Button Name="BtnEdit" Foreground="YellowGreen"  Content="&#xf044;" Width="70" Height="35" Margin="0,0,20,0" Background="Transparent" BorderThickness="0" FontSize="30" Style="{StaticResource FontAwesome}" Click="BtnEdit_Click"/>
            <Button Name="BtnDelete" Foreground="Tomato" Content="&#xf014;" Width="70" Height="35" Margin="20,0,0,0" Background="Transparent" BorderThickness="0" FontSize="30" Style="{StaticResource FontAwesome}" Click="BtnDelete_Click"/>
            <Button Name="BtnExit" Content="&#xf011;" Width="70" Height="35" Margin="40,0,0,0" Background="Transparent" BorderThickness="0" FontSize="30" Style="{StaticResource FontAwesome}" Click="BtnExit_Click"/>
        </StackPanel>

        <!--Hàng 4-->
        <DataGrid Name="DataGrid1" Grid.Row="3" Margin="10,0,10,10" 
                  RenderOptions.ClearTypeHint="Enabled"
                  TextOptions.TextFormattingMode="Display"
                  CanUserAddRows="False"
                  CanUserDeleteRows="False"
                  SelectionUnit="FullRow" 
                  SelectedItem="{Binding DataContext.CurrentSelectedEmployee, Mode=TwoWay}"
                  ItemsSource="{Binding DataContext.Employees, Mode=TwoWay}"
                  AutoGenerateColumns="false"  >

            <DataGrid.Columns>
                <!--Column 1: Employee Id-->
                <DataGridTextColumn Header="Emplyee Id" Binding="{Binding Id}"/>
                
                <!--Column 2: First Name-->
                <DataGridTextColumn Header="First Name" Binding="{Binding FirstName}"/>

                <!--Column 3: Last Name-->
                <DataGridTextColumn Header="Last Name" Binding="{Binding LastName}"/>

                <!--Column 4: Birth Day-->
                <DataGridTemplateColumn Header="Birth Day" >
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <DatePicker SelectedDate="{Binding Birthday}"  BorderThickness="0" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
                
                <!--Column 5: Department Id-->
                <DataGridTemplateColumn Header="Department" >
                    <DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <ComboBox ItemsSource="{Binding DataContext.Departmentses , RelativeSource={RelativeSource AncestorType={x:Type Window}}}"
                                      DisplayMemberPath="Name" SelectedValuePath="Id" SelectedValue="{Binding DepId}" />
                        </DataTemplate>
                    </DataGridTemplateColumn.CellTemplate>
                </DataGridTemplateColumn>
               
            </DataGrid.Columns>
        </DataGrid>
    </Grid>
</Window>
