<Window x:Class="DlgDataGrid"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="Diálogo DataGrid" Height="300" Width="400">
  <Window.Resources>
    <XmlDataProvider x:Key="xmlAlumnos" Source="datos/alumnos.xml"/>
    <!-- Plantillas para configura la sección de detalles de las filas del DataGrid -->
    <!-- PLANTILLA ASIGNATURA -->
    <DataTemplate x:Key="kAsignatura">
      <WrapPanel>
        <TextBlock Text="{Binding XPath=nombre}" Padding="2" />
        <TextBlock Text=":   " />
        <TextBox Text="{Binding XPath=nota}" Padding="2" />
      </WrapPanel>
    </DataTemplate>
    <!-- PLANTILLA ASIGNATURAS -->
    <HierarchicalDataTemplate x:Key="kAsignaturas"
                              ItemsSource="{Binding XPath=asignatura}"
                              ItemTemplate="{StaticResource kAsignatura}">
      <TextBlock Text="{Binding XPath=@tipo}" Padding="2" />
    </HierarchicalDataTemplate>
    <!-- PLANTILLA ALUMNO -->
    <HierarchicalDataTemplate x:Key="kAlumno"
                              ItemsSource="{Binding XPath=asignaturas}"
                              ItemTemplate="{StaticResource kAsignaturas}">
      <TextBlock Text="Asignaturas:" Padding="2" />
    </HierarchicalDataTemplate>
  </Window.Resources>
  <Grid DataContext="{Binding Source={StaticResource xmlAlumnos},  XPath=alumnos}">
    <DataGrid Name="dgAlumnos" Margin="5" AutoGenerateColumns="False" ItemsSource="{Binding XPath=alumno}" LoadingRow="dgAlumnos_LoadingRow">
      <DataGrid.Columns>
        <DataGridTemplateColumn>
          <DataGridTemplateColumn.CellTemplate>
            <DataTemplate>
              <Image Source="{Binding XPath=foto}" Height="32" Width="32"/>
            </DataTemplate>
          </DataGridTemplateColumn.CellTemplate>
        </DataGridTemplateColumn>
        <DataGridTextColumn Header="Nombre" Binding="{Binding XPath=nombre}"/>
        <DataGridTextColumn Header="Dirección" Binding="{Binding XPath=direccion}"/>
        <DataGridTextColumn Header="Estudios" Binding="{Binding XPath=estudios}"/>
        <DataGridCheckBoxColumn Header="Beca" Binding="{Binding XPath=beca}"/>
      </DataGrid.Columns>
      <!-- Sección de detalles de la fila -->
      <DataGrid.RowDetailsTemplate>
        <DataTemplate>
          <Border BorderThickness="0" Background="BlanchedAlmond" Padding="10">
            <TreeView  Name="trvAlumnos" Margin="5"
               ItemsSource="{Binding XPath=.}"
               ItemTemplate="{StaticResource kAlumno}">
            </TreeView>
          </Border>
        </DataTemplate>
      </DataGrid.RowDetailsTemplate>
    </DataGrid>
  </Grid>
</Window>
