<!-- Window1.xaml -->
<Window
  x:Class="WithBinding.Window1"
  xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:local="clr-namespace:WithBinding" 
  Title="WithBinding"
  Height="135"
  Width="200">
  <Window.Resources>
    <local:Person x:Key="Tom" Name="Tom" Age="11" />
    <local:AgeToForegroundConverter x:Key="ageConverter" />
    <local:Base16Converter x:Key="Base16Converter" />
  </Window.Resources>
  <Grid DataContext="{StaticResource Tom}">
    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition Height="Auto" />
      <RowDefinition Height="Auto" />
    </Grid.RowDefinitions>
    <Grid.ColumnDefinitions>
      <ColumnDefinition Width="Auto" />
      <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <TextBlock Grid.Row="0" Grid.Column="0" Margin="5" VerticalAlignment="Center">Name:</TextBlock>
    <TextBox Grid.Row="0" Grid.Column="1" Margin="5" Text="{Binding Path=Name}" />
    <!--<TextBox Grid.Row="0" Grid.Column="1" Margin="5" Text="{Binding Path=Name, Source={StaticResource Tom}}" />-->
    <TextBlock Grid.Row="1" Grid.Column="0" Margin="5" VerticalAlignment="Center">Age:</TextBlock>
    <!--<TextBox Grid.Row="1" Grid.Column="1" Margin="5">
      <TextBox.Text>
        <Binding Path="Age" />
      </TextBox.Text>
    </TextBox>-->
    <!--<TextBox Name="ageTextBox" Grid.Row="1" Grid.Column="1" Margin="5" Text="{Binding Path=Age}"
             Foreground="{Binding Path=Age, Converter={StaticResource ageConverter}}" />-->
    <!--<TextBox Grid.Row="1" Grid.Column="1" Margin="5" Text="{Binding Path=Age, Converter={StaticResource Base16Converter}}"
             Foreground="{Binding Path=Age, Converter={StaticResource ageConverter}}" />-->
    <TextBox Name="ageTextBox" Grid.Row="1" Grid.Column="1" Margin="5"
             Foreground="{Binding Path=Age, Mode=OneWay,
                 Source={StaticResource Tom}, Converter={StaticResource ageConverter}}"
      ToolTip="{Binding RelativeSource={RelativeSource Self}, Path=(Validation.Errors)[0].ErrorContent}">
      <!--ToolTip="{Binding ElementName=ageTextBox, Path=(Validation.Errors)[0].ErrorContent}">-->

      <!--<TextBox.Foreground>
    <Binding Path="Age" Mode="OneWay" Source="{StaticResource Tom}" Converter="{StaticResource ageConverter}" />
  </TextBox.Foreground>-->

      <TextBox.Text>
        <Binding Path="Age" UpdateSourceTrigger="PropertyChanged">
          <!--<Binding Path="Age" NotifyOnValidationError="True">-->
          <Binding.ValidationRules>
            <!--<ExceptionValidationRule />-->
            <local:NumberRangeRule Min="0" Max="128" />
          </Binding.ValidationRules>
        </Binding>
      </TextBox.Text>
    </TextBox>
    <!--<TextBox Grid.Row="1" Grid.Column="1" Margin="5" Text="{Binding Age}" />-->
    <Button Name="birthdayButton" Grid.Row="2" Grid.Column="1" Margin="5" Foreground="{Binding Path=Foreground, ElementName=ageTextBox}">Birthday</Button>
  </Grid>
</Window>
