<navigation:Page xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"  x:Class="ApRiaServices.Formularios" 
           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:riaControls="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.DomainServices"  
           xmlns:ds="clr-namespace:ApRiaServices"
           xmlns:df="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data.DataForm.Toolkit"

           mc:Ignorable="d"
           xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
           d:DesignWidth="640" d:DesignHeight="480"
           Title="Formularios Page">
  <Grid x:Name="LayoutRoot">
    <ScrollViewer x:Name="PageScrollViewer" Style="{StaticResource PageScrollViewerStyle}">

      <StackPanel x:Name="ContentStackPanel" Style="{StaticResource ContentStackPanelStyle}">

        <TextBlock x:Name="HeaderText" Style="{StaticResource HeaderTextStyle}" 
                   Text="{Binding Path=Strings.FormulariosPageTitle,
                   Source={StaticResource ApplicationResources}}"/>

        <!-- Control DomainDataSource -->
        <riaControls:DomainDataSource Name="ddsAlumnos" AutoLoad="True"
                                      QueryName="GetAlumnosQuery"
                                      LoadSize="16"
                                      PageSize="4"
                                      SubmittedChanges="ddsAlumnos_SubmittedChanges">
          <riaControls:DomainDataSource.DomainContext>
            <ds:NotasAlumsDomSvc />
          </riaControls:DomainDataSource.DomainContext>
          <riaControls:DomainDataSource.SortDescriptors>
            <riaControls:SortDescriptor PropertyPath="nombre" Direction="Ascending" />
          </riaControls:DomainDataSource.SortDescriptors>
        </riaControls:DomainDataSource>

        <!-- Lista de alumnos -->
        <TextBlock FontSize="16" Margin="5,10,0,0" Text="Lista de alumnos:"/>
        <sdk:DataPager Margin="5" Source="{Binding Data, ElementName=ddsAlumnos}" />
        <sdk:DataGrid Name="dgAlumnos" Margin="5" Height="Auto"
            AutoGenerateColumns="False" IsReadOnly="True"
            ItemsSource="{Binding Data, ElementName=ddsAlumnos}"
            >
          <sdk:DataGrid.Columns>
            <sdk:DataGridTextColumn Header="ID"
            Binding="{Binding Path=id_alumno}" MinWidth="100"/>
            <sdk:DataGridTextColumn Header="Nombre"
            Binding="{Binding Path=nombre}" MinWidth="260"/>
          </sdk:DataGrid.Columns>
        </sdk:DataGrid>

        <!-- Control DataForm -->
        <df:DataForm x:Name="dfAlumnos" Header="Datos del alumno" Margin="5"
                     AutoGenerateFields="False" 
                     AutoEdit="False" AutoCommit="False"
                     CommitButtonContent="Aceptar" CancelButtonContent="Cancelar"
                     CurrentItem="{Binding SelectedItem, ElementName=dgAlumnos}">
          <df:DataForm.EditTemplate>
            <DataTemplate>
              <StackPanel>
                <df:DataField Label="ID">
                  <TextBox Text="{Binding id_alumno, Mode=OneWay}" />
                </df:DataField>
                <df:DataField Label="Nombre">
                  <TextBox Text="{Binding nombre, Mode=TwoWay}" />
                </df:DataField>
              </StackPanel>
            </DataTemplate>
          </df:DataForm.EditTemplate>
        </df:DataForm>

        <StackPanel Orientation="Horizontal" Margin="0,15,0,0" >
          <Button x:Name="guardarCambios" Content="Guardar cambios"
                  Width="150" Height="23" Margin="5,0,0,0"
                  Click="guardarCambios_Click"/>
          <Button x:Name="agregarAlumno" Content="Agregar alumno"  
                  Width="150" Height="23"  Margin="5,0,0,0"
                  Click="agregarAlumno_Click"/>
          <Button x:Name="borrarAlumno" Content="Borrar alumno"  
                  Width="150" Height="23"  Margin="5,0,0,0"
                  Click="borrarAlumno_Click"/>
        </StackPanel>
      </StackPanel>

    </ScrollViewer>
  </Grid>
</navigation:Page>
