<?xml version="1.0" encoding="utf-8"?>
<UserControl x:Class="GeoDashboard.HomeValueTile" Width="520" Height="360" Margin="6" Foreground="White" FontFamily="Segoe UI" FontSize="24" FontWeight="Light" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:c1="http://schemas.componentone.com/winfx/2006/xaml" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:local="clr-namespace:GeoDashboard">

  <Grid x:Name="LayoutRoot" Background="Black" DataContext="{Binding Path=Sources[USA_Median_Home_Value]}">

    <Grid.Resources>
      <local:IndexDescriptionConverter x:Key="_cvtIndexDescription" />
    </Grid.Resources>

    <Grid.RowDefinitions>
      <RowDefinition Height="Auto" />
      <RowDefinition />
    </Grid.RowDefinitions>

    <Border Style="{StaticResource _tileCaption}">
      <TextBlock Text="Median Home Value" FontSize="12" Foreground="Black" />
    </Border>

    <StackPanel Margin="12" Grid.Row="1">
      <StackPanel Orientation="Horizontal">
        <TextBlock Text="{Binding Dictionary[NAME].Value}" FontWeight="Bold" Foreground="{StaticResource _brResult}" />
        <TextBlock Text="'s median home value is " />
      </StackPanel>
      <TextBlock Text="{Binding Dictionary[MEDVAL_CY].Value, StringFormat=c0}" FontWeight="Bold" Foreground="{StaticResource _brResult}" />
      <TextBlock Text="{Binding Dictionary[MEDVAL_I].Value, Converter={StaticResource _cvtIndexDescription}}" FontSize="12" Foreground="{StaticResource _brResult}" />

      <Grid>
        <Grid.RowDefinitions>
          <RowDefinition />
          <RowDefinition />
          <RowDefinition />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
          <ColumnDefinition Width="auto" />
          <ColumnDefinition />
        </Grid.ColumnDefinitions>

        <TextBlock Text="Median Home Value Index" Grid.Row="0" VerticalAlignment="Center" HorizontalAlignment="Right" FontSize="12" />
        <local:LinearGauge IndexValue="{Binding Dictionary[MEDVAL_I].Value}" Grid.Row="0" Grid.Column="1" Margin="20 0" />

        <TextBlock Text="Median Household Income Index" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Right" FontSize="12" />
        <local:LinearGauge IndexValue="{Binding Dictionary[MEDHINC_I].Value}" Grid.Row="1" Grid.Column="1" Margin="20 0" />

        <TextBlock Text="Median Net Worth Index" Grid.Row="2" VerticalAlignment="Center" HorizontalAlignment="Right" FontSize="12" />
        <local:LinearGauge IndexValue="{Binding Dictionary[MEDNW_I].Value}" Grid.Row="2" Grid.Column="1" Margin="20 0" />
      </Grid>

      <c1:C1FlexGrid ItemsSource="{Binding ShortList}">
        <c1:C1FlexGrid.Columns>
          <c1:Column Binding="{Binding Name}" HorizontalAlignment="Right" Width="*" />
          <c1:Column Binding="{Binding Value, StringFormat=' {0:n0} homes'}" HorizontalAlignment="Right" Width="*" />
          <c1:Column Binding="{Binding Percent, StringFormat=p0}" HorizontalAlignment="Right" Width=".5*" />
          <c1:Column Binding="{Binding Value, StringFormat=n0}" Width="*" CellTemplate="{StaticResource _histoCell}" />
        </c1:C1FlexGrid.Columns>
      </c1:C1FlexGrid>

    </StackPanel>
  </Grid>
</UserControl>