<Window x:Class="DlgAñadir"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:EnlaceDeDatosObjetos"
    Title="DlgAñadir" Height="350" Width="400" ResizeMode="NoResize" ShowInTaskbar="False"
    FocusManager.FocusedElement="{Binding ElementName=ctIdAlumno}">
  <Window.Resources>
    <!-- Plantilla que se aplica a TextBox 
    cuando su contenido no es válido -->
    <ControlTemplate x:Key="PlantillaErrorEnTextBox">
      <DockPanel>
        <Ellipse DockPanel.Dock="Right" 
                 Margin="1,0" Width="8" Height="8"   
                 ToolTip="Dato no válido" >
          <Ellipse.Fill>
            <LinearGradientBrush>
              <GradientStop Color="#11FF1133" Offset="0" />
              <GradientStop Color="#FFFF0000" Offset="1" />
            </LinearGradientBrush>
          </Ellipse.Fill>
        </Ellipse>
        <!-- Lugar que ocupará el TextBox -->
        <AdornedElementPlaceholder />
      </DockPanel>
    </ControlTemplate>
    <!-- Estilo que se aplica al TextBox -->
    <Style TargetType="TextBox" x:Key="EstiloTextBox">
      <Setter Property="Margin" Value="3" />
      <Setter Property="Validation.ErrorTemplate" 
              Value="{StaticResource PlantillaErrorEnTextBox}" />
      <Style.Triggers>
        <Trigger Property="Validation.HasError" Value="True">
          <Setter Property="ToolTip">
            <Setter.Value>
              <Binding Path="(Validation.Errors)[0].ErrorContent"
                       RelativeSource="{x:Static RelativeSource.Self}" />
            </Setter.Value>
          </Setter>
        </Trigger>
      </Style.Triggers>
    </Style>
  </Window.Resources>

  <Border Name="bordeAlumno" Background="LightSteelBlue"
              Padding="7" >
    <Grid Name="gridAlumno">
      <Grid.RowDefinitions>
        <RowDefinition Height="Auto" />
        <RowDefinition Height="*" />
        <RowDefinition Height="Auto" />
      </Grid.RowDefinitions>
      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto" />
          <RowDefinition Height="Auto" />
          <RowDefinition Height="Auto" />
          <RowDefinition Height="Auto" />
          <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="Auto" />
          <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <TextBlock Grid.Row="0" Grid.Column="0" Text="ID: " Margin="7" />
        <TextBox Grid.Row="0" Grid.Column="1" Name="ctIdAlumno" Margin="5"
                 Style="{StaticResource EstiloTextBox}">
          <TextBox.Text>
            <Binding Path="IdAlumno" ConverterCulture="es-ES"
                     UpdateSourceTrigger="PropertyChanged" >
              <Binding.ValidationRules>
                <local:ReglaIdValido IdMin="111" IdMax="999" />
              </Binding.ValidationRules>
            </Binding>
          </TextBox.Text>
        </TextBox>

        <TextBlock Grid.Row="1" Grid.Column="0" Text="Nombre: " Margin="7" />
        <TextBox Grid.Row="1" Grid.Column="1" Name="ctNomAlumno" Margin="5"
                 Style="{StaticResource EstiloTextBox}">
          <TextBox.Text>
            <Binding Path="NomAlumno" ConverterCulture="es-ES" >
              <Binding.ValidationRules>
                <local:ReglaCajaTextoVacia />
              </Binding.ValidationRules>
            </Binding>
          </TextBox.Text>
        </TextBox>

        <TextBlock Grid.Row="2" Grid.Column="0" Text="Dirección: " Margin="7" />
        <TextBox Grid.Row="2" Grid.Column="1" Name="ctDirAlumno" Margin="5"
          Style="{StaticResource EstiloTextBox}">
          <TextBox.Text>
            <Binding Path="DirAlumno" ConverterCulture="es-ES">
              <Binding.ValidationRules>
                <local:ReglaCajaTextoVacia />
              </Binding.ValidationRules>
            </Binding>
          </TextBox.Text>
        </TextBox>

        <TextBlock Grid.Row="3" Grid.Column="0" Text="Estudios: " Margin="7" />
        <TextBox Grid.Row="3" Grid.Column="1" Name="ctEstAlumno" Margin="5"
          Style="{StaticResource EstiloTextBox}">
          <TextBox.Text>
            <Binding Path="EstAlumno" ConverterCulture="es-ES">
              <Binding.ValidationRules>
                <local:ReglaCajaTextoVacia />
              </Binding.ValidationRules>
            </Binding>
          </TextBox.Text>
        </TextBox>

        <TextBlock Grid.Row="4" Grid.Column="0" Text="Beca: " Margin="7" />
        <CheckBox Grid.Row="4" Grid.Column="1" Name="ctBecaAlumno" Margin="5" IsChecked="{Binding Path=BecaAlumno}" />
      </Grid>
      <Grid Grid.Row="1" >
        <Grid.RowDefinitions>
          <RowDefinition Height="Auto" />
          <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
          <ColumnDefinition />
          <ColumnDefinition />
        </Grid.ColumnDefinitions>
        <TextBlock Grid.Row="0" Grid.Column="0" Text="As. Obligatorias: " Margin="7,7,7,1" />
        <TextBlock Grid.Row="0" Grid.Column="1" Text="As. Optativas: " Margin="7,7,7,1" />
        <ListBox Grid.Row="1" Name="lsListaObs" Margin="5" SelectionMode="Extended" />
        <ListBox Grid.Row="1" Grid.Column="1" Name="lsListaOps" Margin="5" SelectionMode="Extended" />
      </Grid>
      <StackPanel Grid.Row="2" Orientation="Horizontal" HorizontalAlignment="Right">
        <Button Name="btAceptar" Content="_Aceptar" Width="72" Margin="7" IsDefault="True" Click="btAceptar_Click" />
        <Button Name="btCancelar" Content="_Cancelar" Width="72" Margin="7" IsCancel="True" />
      </StackPanel>
    </Grid>
  </Border>
</Window>
