<ContentControl x:Class="Microsoft.VisualStudio.TestTools.TestCaseMigrator.FieldMappingView"
                                 xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                                 xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                                 xmlns:TestCaseMigrator="clr-namespace:Microsoft.VisualStudio.TestTools.TestCaseMigrator"
                                 x:ClassModifier="internal">
    <ContentControl.Resources>
        <TestCaseMigrator:BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
        <TestCaseMigrator:InverseBooleanToVisibilityConverter x:Key="InverseBooleanToVisibilityConverter" />

        <DataTemplate x:Key="DSFieldTemplate">
            <TextBlock Text="{Binding DataSourceField}"
                       TextTrimming="CharacterEllipsis"
                       VerticalAlignment="Center"
                       ToolTip="{Binding DataSourceField}">
                <TextBlock.Style>
                    <Style TargetType="{x:Type TextBlock}">
                        <Setter Property="Foreground" Value="Black" />
                        <Style.Triggers>
                            <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}, Path=IsSelected}"
                                         Value="True">
                                <Setter Property="Foreground" Value="White" />
                            </DataTrigger>
                        </Style.Triggers>
                    </Style>
                </TextBlock.Style>
            </TextBlock>

        </DataTemplate>
        <DataTemplate x:Key="WIFieldTemplate">
            <Grid>
                <TextBlock Text="{Binding TFSField, Mode=OneWay}"
                           Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}, 
                                                Mode=OneWay,
                                                Path=IsSelected, Converter={StaticResource InverseBooleanToVisibilityConverter}}"
                           VerticalAlignment="Center" >
                    <TextBlock.Style>
                        <Style TargetType="{x:Type TextBlock}">
                            <Setter Property="Foreground" Value="Gray" />
                            <Style.Triggers>
                                <DataTrigger Binding="{Binding IsValidColumnMapping}"
                                             Value="True">
                                    <Setter Property="Foreground" Value="Black" />
                                </DataTrigger>
                            </Style.Triggers>
                        </Style>
                    </TextBlock.Style>
                </TextBlock>

                <ComboBox x:Name="WIFieldComboBox"
                          SelectedValue="{Binding TFSField, Mode=OneWay}"
                          Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type DataGridRow}}, 
                                                Mode=OneWay,
                                                Path=IsSelected, Converter={StaticResource BooleanToVisibilityConverter}}"
                          SelectionChanged="WIFieldComboBox_SelectionChanged"
                          ItemsSource="{Binding AvailableTFSFields}" />
            </Grid>
        </DataTemplate>

    </ContentControl.Resources>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="*" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
        </Grid.RowDefinitions>

        <DataGrid ItemsSource="{Binding ColumnMappingRows}"
                  x:Name="ColumnMappingControl"
                  AutoGenerateColumns="False"
                  RowHeight="25"
                  GridLinesVisibility="None"
                  CanUserAddRows="False"
                  CanUserDeleteRows="False"
                  CanUserResizeRows="False"
                  CanUserReorderColumns="False"
                  SelectionMode="Single"
                  Grid.Row="0">
            <DataGrid.Columns>
                <DataGridTemplateColumn CellTemplate="{StaticResource DSFieldTemplate}"
                                        Header="Source Field"
                                        HeaderStyle="{DynamicResource DataGridHeaderTextStyle}"
                                        Width="*" />

                <DataGridTemplateColumn Width="*"
                                        Header="Destination Field"
                                        HeaderStyle="{DynamicResource DataGridHeaderTextStyle}"
                                        CellTemplate="{StaticResource WIFieldTemplate}" />
            </DataGrid.Columns>
        </DataGrid>

        <Grid Grid.Row="1">
            <Grid.Style>
                <Style TargetType="{x:Type Grid}">
                    <Setter Property="Visibility" Value="Collapsed" />
                    <Style.Triggers>
                        <DataTrigger Binding="{Binding WizardInfo.DataSourceType}"
                                     Value="{x:Static TestCaseMigrator:DataSourceType.MHT}">
                            <Setter Property="Visibility" Value="Visible" />
                        </DataTrigger>
                    </Style.Triggers>
                </Style>
            </Grid.Style>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="Auto" />
            </Grid.RowDefinitions>

            <CheckBox Grid.Row="0"
                      Margin="0,4,0,0"
                      x:Name="IsFirstLineTitleCheckBox"
                      x:Uid="ColumnMappingView.IsFirstLineTitleCheckBox"
                      AutomationProperties.AutomationId="ColumnMappingView.IsFirstLineTitleCheckBox"
                      AutomationProperties.Name="FirstLineTitleCheckBox"
                      IsChecked="{Binding IsFirstLineTitle}">
                Use the first line of mht/word file as title
            </CheckBox>

            <CheckBox Grid.Row="1"
                      Margin="0,4,0,0"
                      x:Name="IsFileTitleCheckBox"
                      x:Uid="ColumnMappingView.IsFileTitleCheckBox"
                      AutomationProperties.AutomationId="ColumnMappingView.IsFileTitleCheckBox"
                      AutomationProperties.Name="IsFileTitleCheckBox"
                      IsChecked="{Binding IsFileNameTitle}">
                Use the file name of mht/word file as title
            </CheckBox>
        </Grid>

        <TextBlock Text="* Mandatory fields on the destination; all such fields must have the field mapping specified."
                   Margin="0,7,0,0"
                   Grid.Row="2"
                   TextWrapping="Wrap"/>

        <TextBlock Text="+ Fields with values that are auto-generated by the server. The values corresponding to these fields will not be migrated."
                   Margin="0,5,0,0"
                   Grid.Row="3"
                   TextWrapping="Wrap"/>
    </Grid>
</ContentControl>