<!-- Hero module container. -->
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:sc="using:SearchUI.Controls"
                    xmlns:tm="using:SearchUI.TemplateManager"
                    x:Key="EntityContainer.HeroGeneric_8_1_RP">

    <ResourceDictionary.ThemeDictionaries>
        <ResourceDictionary x:Key="Default">
            <SolidColorBrush x:Key="Local.HeroBackgroundBrush"
                             Color="#1D1D1D" />
        </ResourceDictionary>
        <ResourceDictionary x:Key="HighContrast">
            <SolidColorBrush x:Key="Local.HeroBackgroundBrush"
                             Color="{ThemeResource ImmersiveSaturatedBackgroundColor}" />
        </ResourceDictionary>
    </ResourceDictionary.ThemeDictionaries>

    <tm:StringVector x:Key="Local.DominantModuleAutomationId">
        <x:String>@DominantItem.</x:String>
        <x:String>System_ConnectedSearch_RenderingTemplate</x:String>
    </tm:StringVector>
    <tm:StringVector x:Key="Local.BookendModuleAutomationId">
        <x:String>@BookendItem.</x:String>
        <x:String>System_ConnectedSearch_RenderingTemplate</x:String>
    </tm:StringVector>
    <tm:StringVector x:Key="Local.HorizontalModuleAutomationId">
        <x:String>Extended:key</x:String>
        <x:String>@.</x:String>
        <x:String>Extended:size.Extended:horizontal.System_ConnectedSearch_RenderingTemplate</x:String>
    </tm:StringVector>
    <tm:StringVector x:Key="Local.HorizontalLargeModuleAutomationId">
        <x:String>Extended:key</x:String>
        <x:String>@.</x:String>
        <x:String>Extended:size.Extended:horizontalLarge.System_ConnectedSearch_RenderingTemplate</x:String>
    </tm:StringVector>
    <tm:StringVector x:Key="Local.VerticalNarrowModuleAutomationId">
        <x:String>Extended:key</x:String>
        <x:String>@.</x:String>
        <x:String>Extended:size.Extended:verticalNarrow.System_ConnectedSearch_RenderingTemplate</x:String>
    </tm:StringVector>
    <tm:StringVector x:Key="Local.VerticalModuleAutomationId">
        <x:String>Extended:key</x:String>
        <x:String>@.</x:String>
        <x:String>Extended:size.Extended:vertical.System_ConnectedSearch_RenderingTemplate</x:String>
    </tm:StringVector>
    <tm:StringVector x:Key="Local.VerticalLargeModuleAutomationId">
        <x:String>Extended:key</x:String>
        <x:String>@.</x:String>
        <x:String>Extended:size.Extended:verticalLarge.System_ConnectedSearch_RenderingTemplate</x:String>
    </tm:StringVector>
    <tm:StringVector x:Key="Local.AttributionListAutomationId">
        <x:String>@attributionList.</x:String>
        <x:String>Extended:attributionList.System_ConnectedSearch_RenderingTemplate</x:String>
    </tm:StringVector>

    <tm:SwitchCaseConverter x:Key="Local.DominantImageOffsetSwitch"
                            Default="Collapsed">
        <tm:SwitchCase Case="false"
                       Value="Visible" />
    </tm:SwitchCaseConverter>
    <tm:SwitchCaseConverter x:Key="Local.DominantModuleSwitch"
                            Default="Visible">
        <tm:SwitchCase Case="false"
                       Value="Collapsed" />
    </tm:SwitchCaseConverter>

    <!-- The current bounce back distance is approximately 130px. Rounding this up to 500 here so we have 
                     buffer to absorb future bounce back distance variations -->
    <tm:SwitchCaseConverter x:Key="Local.HorizontalBounceBackMarginConverter"
                            Default="0">
        <tm:SwitchCase Case="true"
                       Value="-500, 0, 0, 0" />
    </tm:SwitchCaseConverter>
    <tm:SwitchCaseConverter x:Key="Local.HorizontalBounceBackWidthConverter"
                            Default="0">
        <tm:SwitchCase Case="true"
                       Value="500" />
    </tm:SwitchCaseConverter>
    <tm:SwitchCaseConverter x:Key="Local.VerticalBounceBackMarginConverter"
                            Default="0">
        <tm:SwitchCase Case="true"
                       Value="0, -500, 0, 0" />
    </tm:SwitchCaseConverter>
    <tm:SwitchCaseConverter x:Key="Local.VerticalBounceBackHeightConverter"
                            Default="0">
        <tm:SwitchCase Case="true"
                       Value="500" />
    </tm:SwitchCaseConverter>

    <ControlTemplate x:Key="Local.HorizontalTemplate">

        <Grid VerticalAlignment="Stretch"
              Height="{Binding Path=ContentExtentHeight, ElementName=SearchResultsControl}"
              Width="{Binding Path=ContentExtentWidth, ElementName=SearchResultsControl}"
              Margin="{Binding Source={CustomResource ResultsCommonViewSource}, Path=IsHeroShownFirst, Converter={StaticResource Local.HorizontalBounceBackMarginConverter}}"
              Background="{ThemeResource Local.HeroBackgroundBrush}">

            <Grid.RowDefinitions>
                <!-- Hang point -->
                <RowDefinition Height="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}" />
                <!-- Offset until top of title -->
                <RowDefinition Height="530" />
                <!-- Offset until base of explore modules -->
                <RowDefinition Height="70" />
                <!-- Remaining vertical space -->
                <RowDefinition />
            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>
                <!-- Overpan column -->
                <ColumnDefinition Width="{Binding Source={CustomResource ResultsCommonViewSource}, Path=IsHeroShownFirst, Converter={StaticResource Local.HorizontalBounceBackWidthConverter}}" />
                <!-- Dominant module column -->
                <ColumnDefinition Width="auto" />
                <!-- Info modules column -->
                <ColumnDefinition Width="auto" />
                <!-- Explore modules column -->
                <ColumnDefinition Width="auto" />
                <!-- Bookend module column -->
                <ColumnDefinition Width="auto" />
            </Grid.ColumnDefinitions>

            <Grid.Resources>
                <DataTemplate x:Key="Local.HeroModuleTemplate"
                              tm:GridPositionHelper.RowBindingPath="Extended:size.Extended:horizontal.Extended:row"
                              tm:GridPositionHelper.ColumnBindingPath="Extended:size.Extended:horizontal.Extended:column"
                              tm:GridPositionHelper.RowSpanBindingPath="Extended:size.Extended:horizontal.Extended:rowSpan"
                              tm:GridPositionHelper.ColumnSpanBindingPath="Extended:size.Extended:horizontal.Extended:columnSpan">
                    <sc:ResultContentControl AutomationProperties.AutomationId="{Binding Converter={CustomResource StringPropertyConcatenator}, ConverterParameter={StaticResource Local.HorizontalModuleAutomationId}}"
                                             Content="{Binding}"
                                             ContentTemplate="{Binding Path=Extended:size.Extended:horizontal.System_ConnectedSearch_RenderingTemplate, Converter={CustomResource StringToResource}}"
                                             HorizontalContentAlignment="Stretch"
                                             VerticalContentAlignment="Stretch"
                                             IsTabStop="False" />
                </DataTemplate>
            </Grid.Resources>

            <!-- Dominant module -->
            <sc:ResultContentControl Grid.Row="0"
                                     Grid.Column="1"
                                     Grid.RowSpan="4"
                                     AutomationProperties.AutomationId="{Binding Converter={CustomResource StringPropertyConcatenator}, ConverterParameter={StaticResource Local.DominantModuleAutomationId}}"
                                     DataContext="{Binding Extended:dominantModule}"
                                     Content="{Binding}"
                                     HorizontalContentAlignment="Stretch"
                                     VerticalContentAlignment="Stretch"
                                     IsTabStop="False" />

            <!-- Title -->
            <sc:ResultContentControl Grid.Row="2"
                                     Grid.Column="1"
                                     Grid.RowSpan="2"
                                     Grid.ColumnSpan="2"
                                     HorizontalAlignment="Right"
                                     VerticalAlignment="Top"
                                     Content="{Binding}"
                                     DataContext="{Binding Extended:titleModule}"
                                     IsTabStop="False" />

            <!-- Info modules -->
            <ItemsControl Grid.Row="1"
                          Grid.Column="2"
                          Margin="0, 40, 0, 0"
                          DataContext="{Binding Extended:infoModules}"
                          ItemsSource="{Binding Extended:module}"
                          ItemContainerStyleSelector="{CustomResource GridContainerStyleSelector}"
                          ItemTemplate="{StaticResource Local.HeroModuleTemplate}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <!-- Temporary force the actions module to have a fixed height until it is moved into its own container
                        <Grid tm:GridHelper.RowDefinitionsQuantity="{Binding Extended:size.Extended:horizontal.Extended:rows}"
                              tm:GridHelper.ColumnDefinitionsQuantity="{Binding Extended:size.Extended:horizontal.Extended:columns}"
                              tm:GridHelper.ColumnLength="160"/> -->
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition Height="130" />
                                <RowDefinition Height="130" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="160" />
                                <ColumnDefinition Width="160" />
                            </Grid.ColumnDefinitions>
                        </Grid>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>

            <!-- Sidekick highlight -->
            <Grid Grid.Row="0"
                  Grid.Column="3"
                  Grid.RowSpan="4"
                  HorizontalAlignment="Left"
                  tm:GridHelper.ColumnDefinitionsQuantity="{Binding Extended:exploreModules.Extended:module[0].Extended:size.Extended:horizontal.Extended:columnSpan}"
                  tm:GridHelper.ColumnLength="160"
                  Style="{CustomResource Resources.Shared.HeroSideKickAccentStyle}" />

            <!-- Explore modules -->
            <ItemsControl Grid.Row="1"
                          Grid.Column="3"
                          Grid.RowSpan="2"
                          DataContext="{Binding Extended:exploreModules}"
                          ItemsSource="{Binding Extended:module}"
                          ItemContainerStyleSelector="{CustomResource GridContainerStyleSelector}"
                          ItemTemplate="{StaticResource Local.HeroModuleTemplate}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Grid tm:GridHelper.RowDefinitionsQuantity="{Binding Extended:size.Extended:horizontal.Extended:rows}"
                              tm:GridHelper.ColumnDefinitionsQuantity="{Binding Extended:size.Extended:horizontal.Extended:columns}"
                              tm:GridHelper.RowLength="150"
                              tm:GridHelper.ColumnLength="160" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>

            <!-- Attribution module -->
            <sc:ResultContentControl Grid.Row="3"
                                     Grid.Column="1"
                                     Grid.ColumnSpan="3"
                                     AutomationProperties.AutomationId="{Binding Converter={CustomResource StringPropertyConcatenator}, ConverterParameter={StaticResource Local.AttributionListAutomationId}}"
                                     Margin="0, 0, 30, 25"
                                     Content="{Binding Extended:attributionList}"
                                     ContentTemplateSelector="{CustomResource GenericDataTemplateSelector}"
                                     HorizontalAlignment="Right"
                                     VerticalAlignment="Bottom"
                                     IsTabStop="False" />

            <!-- Bookend module -->
            <sc:ResultContentControl Grid.Row="0"
                                     Grid.Column="4"
                                     Grid.RowSpan="4"
                                     AutomationProperties.AutomationId="{Binding Converter={CustomResource StringPropertyConcatenator}, ConverterParameter={StaticResource Local.BookendModuleAutomationId}}"
                                     DataContext="{Binding Extended:bookendModule}"
                                     Content="{Binding}"
                                     HorizontalContentAlignment="Stretch"
                                     VerticalContentAlignment="Stretch"
                                     IsTabStop="False" />

        </Grid>

    </ControlTemplate>
    
    <ControlTemplate x:Key="Local.HorizontalLargeTemplate">

        <Grid VerticalAlignment="Stretch"
              Height="{Binding Path=ContentExtentHeight, ElementName=SearchResultsControl}"
              Width="{Binding Path=ContentExtentWidth, ElementName=SearchResultsControl}"
              Margin="{Binding Source={CustomResource ResultsCommonViewSource}, Path=IsHeroShownFirst, Converter={StaticResource Local.HorizontalBounceBackMarginConverter}}"
              Background="{ThemeResource Local.HeroBackgroundBrush}">

            <Grid.RowDefinitions>
                <!-- Hang point -->
                <RowDefinition Height="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}" />
                <!-- Offset until top of title -->
                <RowDefinition Height="530" />
                <!-- Offset until base of explore modules -->
                <RowDefinition Height="70" />
                <!-- Remaining vertical space -->
                <RowDefinition />
            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>
                <!-- Overpan column -->
                <ColumnDefinition Width="{Binding Source={CustomResource ResultsCommonViewSource}, Path=IsHeroShownFirst, Converter={StaticResource Local.HorizontalBounceBackWidthConverter}}" />
                <!-- Dominant module column -->
                <ColumnDefinition Width="auto" />
                <!-- Info modules column -->
                <ColumnDefinition Width="auto" />
                <!-- Explore modules column -->
                <ColumnDefinition Width="auto" />
                <!-- Bookend module column -->
                <ColumnDefinition Width="auto" />
            </Grid.ColumnDefinitions>

            <Grid.Resources>
                <DataTemplate x:Key="Local.HeroModuleTemplate"
                              tm:GridPositionHelper.RowBindingPath="Extended:size.Extended:horizontalLarge.Extended:row"
                              tm:GridPositionHelper.ColumnBindingPath="Extended:size.Extended:horizontalLarge.Extended:column"
                              tm:GridPositionHelper.RowSpanBindingPath="Extended:size.Extended:horizontalLarge.Extended:rowSpan"
                              tm:GridPositionHelper.ColumnSpanBindingPath="Extended:size.Extended:horizontalLarge.Extended:columnSpan">
                    <sc:ResultContentControl AutomationProperties.AutomationId="{Binding Converter={CustomResource StringPropertyConcatenator}, ConverterParameter={StaticResource Local.HorizontalLargeModuleAutomationId}}"
                                             Content="{Binding}"
                                             ContentTemplate="{Binding Path=Extended:size.Extended:horizontalLarge.System_ConnectedSearch_RenderingTemplate, Converter={CustomResource StringToResource}}"
                                             HorizontalContentAlignment="Stretch"
                                             VerticalContentAlignment="Stretch"
                                             IsTabStop="False" />
                </DataTemplate>
            </Grid.Resources>

            <!-- Dominant module -->
            <sc:ResultContentControl Grid.Row="0"
                                     Grid.Column="1"
                                     Grid.RowSpan="4"
                                     AutomationProperties.AutomationId="{Binding Converter={CustomResource StringPropertyConcatenator}, ConverterParameter={StaticResource Local.DominantModuleAutomationId}}"
                                     DataContext="{Binding Extended:dominantModule}"
                                     Content="{Binding}"
                                     HorizontalContentAlignment="Stretch"
                                     VerticalContentAlignment="Stretch"
                                     IsTabStop="False" />

            <!-- Title -->
            <sc:ResultContentControl Grid.Row="2"
                                     Grid.Column="1"
                                     Grid.RowSpan="2"
                                     Grid.ColumnSpan="2"
                                     HorizontalAlignment="Right"
                                     VerticalAlignment="Top"
                                     Content="{Binding}"
                                     DataContext="{Binding Extended:titleModule}"
                                     IsTabStop="False" />

            <!-- Info modules -->
            <ItemsControl Grid.Row="1"
                          Grid.Column="2"
                          Margin="0, 40, 0, 0"
                          DataContext="{Binding Extended:infoModules}"
                          ItemsSource="{Binding Extended:module}"
                          ItemContainerStyleSelector="{CustomResource GridContainerStyleSelector}"
                          ItemTemplate="{StaticResource Local.HeroModuleTemplate}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <!-- Temporary force the actions module to have a fixed height until it is moved into its own container
                        <Grid tm:GridHelper.RowDefinitionsQuantity="{Binding Extended:size.Extended:horizontalLarge.Extended:rows}"
                              tm:GridHelper.ColumnDefinitionsQuantity="{Binding Extended:size.Extended:horizontalLarge.Extended:columns}"
                              tm:GridHelper.ColumnLength="160"/> -->
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition />
                                <RowDefinition />
                                <RowDefinition Height="130" />
                                <RowDefinition Height="130" />
                            </Grid.RowDefinitions>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="160" />
                                <ColumnDefinition Width="160" />
                            </Grid.ColumnDefinitions>
                        </Grid>
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>

            <!-- Sidekick highlight -->
            <Grid Grid.Row="0"
                  Grid.Column="3"
                  Grid.RowSpan="4"
                  HorizontalAlignment="Left"
                  tm:GridHelper.ColumnDefinitionsQuantity="{Binding Extended:exploreModules.Extended:module[0].Extended:size.Extended:horizontalLarge.Extended:columnSpan}"
                  tm:GridHelper.ColumnLength="160"
                  Style="{CustomResource Resources.Shared.HeroSideKickAccentStyle}" />

            <!-- Explore modules -->
            <ItemsControl Grid.Row="1"
                          Grid.Column="3"
                          Grid.RowSpan="2"
                          DataContext="{Binding Extended:exploreModules}"
                          ItemsSource="{Binding Extended:module}"
                          ItemContainerStyleSelector="{CustomResource GridContainerStyleSelector}"
                          ItemTemplate="{StaticResource Local.HeroModuleTemplate}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Grid tm:GridHelper.RowDefinitionsQuantity="{Binding Extended:size.Extended:horizontalLarge.Extended:rows}"
                              tm:GridHelper.ColumnDefinitionsQuantity="{Binding Extended:size.Extended:horizontalLarge.Extended:columns}"
                              tm:GridHelper.RowLength="150"
                              tm:GridHelper.ColumnLength="160" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>

            <!-- Attribution module -->
            <sc:ResultContentControl Grid.Row="3"
                                     Grid.Column="1"
                                     Grid.ColumnSpan="3"
                                     AutomationProperties.AutomationId="{Binding Converter={CustomResource StringPropertyConcatenator}, ConverterParameter={StaticResource Local.AttributionListAutomationId}}"
                                     Margin="0, 0, 30, 25"
                                     Content="{Binding Extended:attributionList}"
                                     ContentTemplateSelector="{CustomResource GenericDataTemplateSelector}"
                                     HorizontalAlignment="Right"
                                     VerticalAlignment="Bottom"
                                     IsTabStop="False" />

            <!-- Bookend module -->
            <sc:ResultContentControl Grid.Row="0"
                                     Grid.Column="4"
                                     Grid.RowSpan="4"
                                     AutomationProperties.AutomationId="{Binding Converter={CustomResource StringPropertyConcatenator}, ConverterParameter={StaticResource Local.BookendModuleAutomationId}}"
                                     DataContext="{Binding Extended:bookendModule}"
                                     Content="{Binding}"
                                     HorizontalContentAlignment="Stretch"
                                     VerticalContentAlignment="Stretch"
                                     IsTabStop="False" />

        </Grid>

    </ControlTemplate>
    
    <ControlTemplate x:Key="Local.VerticalNarrowTemplate">

        <Grid HorizontalAlignment="Stretch"
              Height="{Binding Path=ContentExtentHeight, ElementName=SearchResultsControl}"
              Width="{Binding Path=ContentExtentWidth, ElementName=SearchResultsControl}"
              Margin="{Binding Source={CustomResource ResultsCommonViewSource}, Path=IsHeroShownFirst, Converter={StaticResource Local.VerticalBounceBackMarginConverter}}"
              Background="{ThemeResource Local.HeroBackgroundBrush}">

            <Grid.RowDefinitions>
                <!-- Overpan row -->
                <RowDefinition Height="{Binding Source={CustomResource ResultsCommonViewSource}, Path=IsHeroShownFirst, Converter={StaticResource Local.VerticalBounceBackHeightConverter}}" />
                <!-- Dominant module row -->
                <RowDefinition Height="auto" />
                <!-- Title row -->
                <RowDefinition Height="auto" />
                <!-- Info modules row -->
                <RowDefinition Height="auto" />
                <!-- Explore modules row -->
                <RowDefinition Height="auto" />
                <!-- Attribution module -->
                <RowDefinition Height="auto" />
                <!-- Bookend module row -->
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>
                <!-- Hang point -->
                <ColumnDefinition Width="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}" />
                <!-- Modules -->
                <ColumnDefinition Width="auto" />
                <!-- Remaining horizontal space -->
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <Grid.Resources>
                <DataTemplate x:Key="Local.HeroModuleTemplate"
                              tm:GridPositionHelper.RowBindingPath="Extended:size.Extended:verticalNarrow.Extended:row"
                              tm:GridPositionHelper.ColumnBindingPath="Extended:size.Extended:verticalNarrow.Extended:column"
                              tm:GridPositionHelper.RowSpanBindingPath="Extended:size.Extended:verticalNarrow.Extended:rowSpan"
                              tm:GridPositionHelper.ColumnSpanBindingPath="Extended:size.Extended:verticalNarrow.Extended:columnSpan">
                    <sc:ResultContentControl AutomationProperties.AutomationId="{Binding Converter={CustomResource StringPropertyConcatenator}, ConverterParameter={StaticResource Local.VerticalNarrowModuleAutomationId}}"
                                             Content="{Binding}"
                                             ContentTemplate="{Binding Path=Extended:size.Extended:verticalNarrow.System_ConnectedSearch_RenderingTemplate, Converter={CustomResource StringToResource}}"
                                             HorizontalContentAlignment="Stretch"
                                             VerticalContentAlignment="Stretch"
                                             IsTabStop="False" />
                </DataTemplate>
            </Grid.Resources>

            <!-- Optional spacing in the case of no dominant image -->
            <Rectangle Grid.Row="1"
                       Grid.Column="0"
                       Grid.ColumnSpan="3"
                       Visibility="{Binding Extended:titleModule.Extended:title.Extended:hasDominantModule, Converter={StaticResource Local.DominantImageOffsetSwitch}}"
                       Width="{TemplateBinding Tag}"
                       Margin="0,0,0,100" />

            <!-- Dominant module -->
            <sc:ResultContentControl Grid.Row="1"
                                     Grid.Column="0"
                                     Grid.ColumnSpan="3"
                                     AutomationProperties.AutomationId="{Binding Converter={CustomResource StringPropertyConcatenator}, ConverterParameter={StaticResource Local.DominantModuleAutomationId}}"
                                     DataContext="{Binding Extended:dominantModule}"
                                     Content="{Binding}"
                                     HorizontalContentAlignment="Stretch"
                                     VerticalContentAlignment="Stretch"
                                     IsTabStop="False" />

            <!-- Title -->
            <Grid Grid.Row="2"
                  Grid.Column="0"
                  Grid.ColumnSpan="3"
                  HorizontalAlignment="Left"
                  Margin="0, -20, 0, 0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <sc:ResultContentControl Grid.Row="0"
                                         Grid.Column="1"
                                         DataContext="{Binding Extended:titleModule}"
                                         Content="{Binding}"
                                         IsTabStop="False" />
            </Grid>

            <!-- Info modules -->
            <ItemsControl Grid.Row="3"
                          Grid.Column="1"
                          DataContext="{Binding Extended:infoModules}"
                          ItemsSource="{Binding Extended:module}"
                          ItemContainerStyleSelector="{CustomResource GridContainerStyleSelector}"
                          ItemTemplate="{StaticResource Local.HeroModuleTemplate}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Grid tm:GridHelper.RowDefinitionsQuantity="{Binding Extended:size.Extended:verticalNarrow.Extended:rows}"
                              tm:GridHelper.ColumnDefinitionsQuantity="{Binding Extended:size.Extended:verticalNarrow.Extended:columns}"
                              tm:GridHelper.ColumnLength="160" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>

            <!-- Sidekick highlight -->
            <Grid Grid.Row="4"
                  Grid.Column="0"
                  Grid.ColumnSpan="3"
                  VerticalAlignment="Top"
                  tm:GridHelper.RowDefinitionsQuantity="{Binding Extended:exploreModules.Extended:module[0].Extended:size.Extended:verticalNarrow.Extended:rowSpan}"
                  tm:GridHelper.RowLength="150"
                  Style="{CustomResource Resources.Shared.HeroSideKickAccentStyle}" />

            <!-- Explore modules -->
            <ItemsControl Grid.Row="4"
                          Grid.Column="1"
                          DataContext="{Binding Extended:exploreModules}"
                          ItemsSource="{Binding Extended:module}"
                          ItemContainerStyleSelector="{CustomResource GridContainerStyleSelector}"
                          ItemTemplate="{StaticResource Local.HeroModuleTemplate}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Grid tm:GridHelper.RowDefinitionsQuantity="{Binding Extended:size.Extended:verticalNarrow.Extended:rows}"
                              tm:GridHelper.ColumnDefinitionsQuantity="{Binding Extended:size.Extended:verticalNarrow.Extended:columns}"
                              tm:GridHelper.RowLength="150"
                              tm:GridHelper.ColumnLength="160" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>

            <!-- Attribution module -->
            <sc:ResultContentControl Grid.Row="5"
                                     Grid.Column="1"
                                     AutomationProperties.AutomationId="{Binding Converter={CustomResource StringPropertyConcatenator}, ConverterParameter={StaticResource Local.AttributionListAutomationId}}"
                                     Margin="30, 36, 30, 10"
                                     Content="{Binding Extended:attributionList}"
                                     ContentTemplateSelector="{CustomResource GenericDataTemplateSelector}"
                                     IsTabStop="False" />

            <!-- Bookend module -->
            <sc:ResultContentControl Grid.Row="6"
                                     Grid.Column="0"
                                     Grid.ColumnSpan="3"
                                     AutomationProperties.AutomationId="{Binding Converter={CustomResource StringPropertyConcatenator}, ConverterParameter={StaticResource Local.BookendModuleAutomationId}}"
                                     DataContext="{Binding Extended:bookendModule}"
                                     Content="{Binding}"
                                     HorizontalContentAlignment="Stretch"
                                     VerticalContentAlignment="Stretch"
                                     IsTabStop="False" />

        </Grid>

    </ControlTemplate>

    <ControlTemplate x:Key="Local.VerticalTemplate">

        <Grid HorizontalAlignment="Stretch"
              Height="{Binding Path=ContentExtentHeight, ElementName=SearchResultsControl}"
              Width="{Binding Path=ContentExtentWidth, ElementName=SearchResultsControl}"
              Margin="{Binding Source={CustomResource ResultsCommonViewSource}, Path=IsHeroShownFirst, Converter={StaticResource Local.VerticalBounceBackMarginConverter}}"
              Background="{ThemeResource Local.HeroBackgroundBrush}">

            <Grid.RowDefinitions>
                <!-- Overpan row -->
                <RowDefinition Height="{Binding Source={CustomResource ResultsCommonViewSource}, Path=IsHeroShownFirst, Converter={StaticResource Local.VerticalBounceBackHeightConverter}}" />
                <!-- Dominant module row -->
                <RowDefinition Height="auto" />
                <!-- Title row -->
                <RowDefinition Height="auto" />
                <!-- Info modules row -->
                <RowDefinition Height="auto" />
                <!-- Explore modules row -->
                <RowDefinition Height="auto" />
                <!-- Attribution module -->
                <RowDefinition Height="auto" />
                <!-- Bookend module row -->
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>
                <!-- Hang point -->
                <ColumnDefinition Width="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}" />
                <!-- Modules -->
                <ColumnDefinition Width="auto" />
                <!-- Remaining horizontal space -->
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <Grid.Resources>
                <DataTemplate x:Key="Local.HeroModuleTemplate"
                              tm:GridPositionHelper.RowBindingPath="Extended:size.Extended:vertical.Extended:row"
                              tm:GridPositionHelper.ColumnBindingPath="Extended:size.Extended:vertical.Extended:column"
                              tm:GridPositionHelper.RowSpanBindingPath="Extended:size.Extended:vertical.Extended:rowSpan"
                              tm:GridPositionHelper.ColumnSpanBindingPath="Extended:size.Extended:vertical.Extended:columnSpan">
                    <sc:ResultContentControl AutomationProperties.AutomationId="{Binding Converter={CustomResource StringPropertyConcatenator}, ConverterParameter={StaticResource Local.VerticalModuleAutomationId}}"
                                             Content="{Binding}"
                                             ContentTemplate="{Binding Path=Extended:size.Extended:vertical.System_ConnectedSearch_RenderingTemplate, Converter={CustomResource StringToResource}}"
                                             HorizontalContentAlignment="Stretch"
                                             VerticalContentAlignment="Stretch"
                                             IsTabStop="False" />
                </DataTemplate>
            </Grid.Resources>

            <!-- Optional Spacer for the case when we have no dominant image -->
            <Rectangle Grid.Row="1"
                       Grid.Column="0"
                       Grid.ColumnSpan="3"
                       Visibility="{Binding Extended:titleModule.Extended:title.Extended:hasDominantModule, Converter={StaticResource Local.DominantImageOffsetSwitch}}"
                       Width="{TemplateBinding Tag}"
                       Margin="0,0,0,100" />

            <!-- Dominant module -->
            <sc:ResultContentControl Grid.Row="1"
                                     Grid.Column="0"
                                     Grid.ColumnSpan="3"
                                     AutomationProperties.AutomationId="{Binding Converter={CustomResource StringPropertyConcatenator}, ConverterParameter={StaticResource Local.DominantModuleAutomationId}}"
                                     DataContext="{Binding Extended:dominantModule}"
                                     Content="{Binding}"
                                     HorizontalContentAlignment="Stretch"
                                     VerticalContentAlignment="Stretch"
                                     IsTabStop="False" />

            <!-- Title -->
            <Grid Grid.Row="2"
                  Grid.Column="0"
                  Grid.ColumnSpan="3"
                  HorizontalAlignment="Left"
                  Margin="0, -20, 0, 0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Rectangle Style="{CustomResource Resources.Shared.HeroTitleAccentStyle}"
                           Visibility="{Binding Extended:TitleModule.Extended:Title.Extended:hasDominantModule, Converter={StaticResource Local.DominantModuleSwitch}}" />
                <sc:ResultContentControl Grid.Row="0"
                                         Grid.Column="1"
                                         DataContext="{Binding Extended:titleModule}"
                                         Content="{Binding}"
                                         IsTabStop="False" />
            </Grid>

            <!-- Info modules -->
            <ItemsControl Grid.Row="3"
                          Grid.Column="1"
                          DataContext="{Binding Extended:infoModules}"
                          ItemsSource="{Binding Extended:module}"
                          ItemContainerStyleSelector="{CustomResource GridContainerStyleSelector}"
                          ItemTemplate="{StaticResource Local.HeroModuleTemplate}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Grid tm:GridHelper.RowDefinitionsQuantity="{Binding Extended:size.Extended:vertical.Extended:rows}"
                              tm:GridHelper.ColumnDefinitionsQuantity="{Binding Extended:size.Extended:vertical.Extended:columns}"
                              tm:GridHelper.ColumnLength="160" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>

            <!-- Sidekick highlight -->
            <Grid Grid.Row="4"
                  Grid.Column="0"
                  Grid.ColumnSpan="3"
                  VerticalAlignment="Top"
                  tm:GridHelper.RowDefinitionsQuantity="{Binding Extended:exploreModules.Extended:module[0].Extended:size.Extended:vertical.Extended:rowSpan}"
                  tm:GridHelper.RowLength="150"
                  Style="{CustomResource Resources.Shared.HeroSideKickAccentStyle}" />

            <!-- Explore modules -->
            <ItemsControl Grid.Row="4"
                          Grid.Column="1"
                          DataContext="{Binding Extended:exploreModules}"
                          ItemsSource="{Binding Extended:module}"
                          ItemContainerStyleSelector="{CustomResource GridContainerStyleSelector}"
                          ItemTemplate="{StaticResource Local.HeroModuleTemplate}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Grid tm:GridHelper.RowDefinitionsQuantity="{Binding Extended:size.Extended:vertical.Extended:rows}"
                              tm:GridHelper.ColumnDefinitionsQuantity="{Binding Extended:size.Extended:vertical.Extended:columns}"
                              tm:GridHelper.RowLength="150"
                              tm:GridHelper.ColumnLength="160" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>

            <!-- Attribution module -->
            <sc:ResultContentControl Grid.Row="5"
                                     Grid.Column="1"
                                     AutomationProperties.AutomationId="{Binding Converter={CustomResource StringPropertyConcatenator}, ConverterParameter={StaticResource Local.AttributionListAutomationId}}"
                                     Margin="30, 36, 30, 10"
                                     Content="{Binding Extended:attributionList}"
                                     ContentTemplateSelector="{CustomResource GenericDataTemplateSelector}"
                                     IsTabStop="False" />

            <!-- Bookend module -->
            <sc:ResultContentControl Grid.Row="6"
                                     Grid.Column="0"
                                     Grid.ColumnSpan="3"
                                     AutomationProperties.AutomationId="{Binding Converter={CustomResource StringPropertyConcatenator}, ConverterParameter={StaticResource Local.BookendModuleAutomationId}}"
                                     DataContext="{Binding Extended:bookendModule}"
                                     Content="{Binding}"
                                     HorizontalContentAlignment="Stretch"
                                     VerticalContentAlignment="Stretch"
                                     IsTabStop="False" />

        </Grid>

    </ControlTemplate>
    
    <ControlTemplate x:Key="Local.VerticalLargeTemplate">

        <Grid HorizontalAlignment="Stretch"
              Height="{Binding Path=ContentExtentHeight, ElementName=SearchResultsControl}"
              Width="{Binding Path=ContentExtentWidth, ElementName=SearchResultsControl}"
              Margin="{Binding Source={CustomResource ResultsCommonViewSource}, Path=IsHeroShownFirst, Converter={StaticResource Local.VerticalBounceBackMarginConverter}}"
              Background="{ThemeResource Local.HeroBackgroundBrush}">

            <Grid.RowDefinitions>
                <!-- Overpan row -->
                <RowDefinition Height="{Binding Source={CustomResource ResultsCommonViewSource}, Path=IsHeroShownFirst, Converter={StaticResource Local.VerticalBounceBackHeightConverter}}" />
                <!-- Dominant module row -->
                <RowDefinition Height="auto" />
                <!-- Title row -->
                <RowDefinition Height="auto" />
                <!-- Info modules row -->
                <RowDefinition Height="auto" />
                <!-- Explore modules row -->
                <RowDefinition Height="auto" />
                <!-- Attribution module -->
                <RowDefinition Height="auto" />
                <!-- Bookend module row -->
                <RowDefinition Height="auto" />
            </Grid.RowDefinitions>

            <Grid.ColumnDefinitions>
                <!-- Hang point -->
                <ColumnDefinition Width="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}" />
                <!-- Modules -->
                <ColumnDefinition Width="auto" />
                <!-- Remaining horizontal space -->
                <ColumnDefinition />
            </Grid.ColumnDefinitions>

            <Grid.Resources>
                <DataTemplate x:Key="Local.HeroModuleTemplate"
                              tm:GridPositionHelper.RowBindingPath="Extended:size.Extended:verticalLarge.Extended:row"
                              tm:GridPositionHelper.ColumnBindingPath="Extended:size.Extended:verticalLarge.Extended:column"
                              tm:GridPositionHelper.RowSpanBindingPath="Extended:size.Extended:verticalLarge.Extended:rowSpan"
                              tm:GridPositionHelper.ColumnSpanBindingPath="Extended:size.Extended:verticalLarge.Extended:columnSpan">
                    <sc:ResultContentControl AutomationProperties.AutomationId="{Binding Converter={CustomResource StringPropertyConcatenator}, ConverterParameter={StaticResource Local.VerticalLargeModuleAutomationId}}"
                                             Content="{Binding}"
                                             ContentTemplate="{Binding Path=Extended:size.Extended:verticalLarge.System_ConnectedSearch_RenderingTemplate, Converter={CustomResource StringToResource}}"
                                             HorizontalContentAlignment="Stretch"
                                             VerticalContentAlignment="Stretch"
                                             IsTabStop="False" />
                </DataTemplate>
            </Grid.Resources>

            <!-- Optional Spacer for the case when we have no dominant image -->
            <Rectangle Grid.Row="1" 
                       Grid.Column="0" 
                       Grid.ColumnSpan="3"
                       Visibility="{Binding Extended:titleModule.Extended:title.Extended:hasDominantModule, Converter={StaticResource Local.DominantImageOffsetSwitch}}"
                       Width="{TemplateBinding Tag}"
                       Margin="0,0,0,100"/>

            <!-- Dominant module -->    
            <sc:ResultContentControl Grid.Row="1"
                                     Grid.Column="0" 
                                     Grid.ColumnSpan="3"
                                     AutomationProperties.AutomationId="{Binding Converter={CustomResource StringPropertyConcatenator}, ConverterParameter={StaticResource Local.DominantModuleAutomationId}}"
                                     DataContext="{Binding Extended:dominantModule}"
                                     Content="{Binding}"
                                     HorizontalContentAlignment="Stretch"
                                     VerticalContentAlignment="Stretch"
                                     IsTabStop="False" />

            <!-- Title -->
            <Grid Grid.Row="2"
                  Grid.Column="0"
                  Grid.ColumnSpan="3"
                  HorizontalAlignment="Left"
                  Margin="0, -20, 0, 0">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}" />
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Rectangle Style="{CustomResource Resources.Shared.HeroTitleAccentStyle}"
                           Visibility="{Binding Extended:TitleModule.Extended:Title.Extended:hasDominantModule, Converter={StaticResource Local.DominantModuleSwitch}}"/>
                <sc:ResultContentControl Grid.Row="0"
                                         Grid.Column="1"
                                         DataContext="{Binding Extended:titleModule}"
                                         Content="{Binding}"
                                         IsTabStop="False" />
            </Grid>

            <!-- Info modules -->
            <ItemsControl Grid.Row="3"
                          Grid.Column="1"
                          DataContext="{Binding Extended:infoModules}"
                          ItemsSource="{Binding Extended:module}"
                          ItemContainerStyleSelector="{CustomResource GridContainerStyleSelector}"
                          ItemTemplate="{StaticResource Local.HeroModuleTemplate}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Grid tm:GridHelper.RowDefinitionsQuantity="{Binding Extended:size.Extended:verticalLarge.Extended:rows}"
                              tm:GridHelper.ColumnDefinitionsQuantity="{Binding Extended:size.Extended:verticalLarge.Extended:columns}"
                              tm:GridHelper.ColumnLength="160" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>

            <!-- Sidekick highlight -->
            <Grid Grid.Row="4"
                  Grid.Column="0"
                  Grid.ColumnSpan="3"
                  VerticalAlignment="Top"
                  tm:GridHelper.RowDefinitionsQuantity="{Binding Extended:exploreModules.Extended:module[0].Extended:size.Extended:verticalLarge.Extended:rowSpan}"
                  tm:GridHelper.RowLength="150"
                  Style="{CustomResource Resources.Shared.HeroSideKickAccentStyle}" />

            <!-- Explore modules -->
            <ItemsControl Grid.Row="4"
                          Grid.Column="1"
                          DataContext="{Binding Extended:exploreModules}"
                          ItemsSource="{Binding Extended:module}"
                          ItemContainerStyleSelector="{CustomResource GridContainerStyleSelector}"
                          ItemTemplate="{StaticResource Local.HeroModuleTemplate}">
                <ItemsControl.ItemsPanel>
                    <ItemsPanelTemplate>
                        <Grid tm:GridHelper.RowDefinitionsQuantity="{Binding Extended:size.Extended:verticalLarge.Extended:rows}"
                              tm:GridHelper.ColumnDefinitionsQuantity="{Binding Extended:size.Extended:verticalLarge.Extended:columns}"
                              tm:GridHelper.RowLength="150"
                              tm:GridHelper.ColumnLength="160" />
                    </ItemsPanelTemplate>
                </ItemsControl.ItemsPanel>
            </ItemsControl>

            <!-- Attribution module -->
            <sc:ResultContentControl Grid.Row="5"
                                     Grid.Column="1"
                                     AutomationProperties.AutomationId="{Binding Converter={CustomResource StringPropertyConcatenator}, ConverterParameter={StaticResource Local.AttributionListAutomationId}}"
                                     Margin="30, 36, 30, 10"
                                     Content="{Binding Extended:attributionList}"
                                     ContentTemplateSelector="{CustomResource GenericDataTemplateSelector}"
                                     IsTabStop="False" />

            <!-- Bookend module -->
            <sc:ResultContentControl Grid.Row="6"
                                     Grid.Column="0"
                                     Grid.ColumnSpan="3"
                                     AutomationProperties.AutomationId="{Binding Converter={CustomResource StringPropertyConcatenator}, ConverterParameter={StaticResource Local.BookendModuleAutomationId}}"
                                     DataContext="{Binding Extended:bookendModule}"
                                     Content="{Binding}"
                                     HorizontalContentAlignment="Stretch"
                                     VerticalContentAlignment="Stretch"
                                     IsTabStop="False" />

        </Grid>

    </ControlTemplate>
    
    <Style x:Key="Horizontal"
           TargetType="ContentControl">
        <Setter Property="Template"
                Value="{StaticResource Local.HorizontalTemplate}" />
        <Setter Property="Tag"
                Value="80" />
        <Setter Property="RequestedTheme"
                Value="Dark" />
    </Style>
    <Style x:Key="HorizontalLarge"
           TargetType="ContentControl">
        <Setter Property="Template"
                Value="{StaticResource Local.HorizontalLargeTemplate}" />
        <Setter Property="Tag"
                Value="220" />
        <Setter Property="RequestedTheme"
                Value="Dark" />
    </Style>
    <Style x:Key="VerticalNarrow"
           TargetType="ContentControl">
        <Setter Property="Template"
                Value="{StaticResource Local.VerticalNarrowTemplate}" />
        <Setter Property="Tag"
                Value="0" />
        <Setter Property="RequestedTheme"
                Value="Dark" />
    </Style>
    <Style x:Key="Vertical"
           TargetType="ContentControl">
        <Setter Property="Template"
                Value="{StaticResource Local.VerticalTemplate}" />
        <Setter Property="Tag"
                Value="20" />
        <Setter Property="RequestedTheme"
                Value="Dark" />
    </Style>
    <Style x:Key="VerticalLarge"
           TargetType="ContentControl">
        <Setter Property="Template"
                Value="{StaticResource Local.VerticalLargeTemplate}" />
        <Setter Property="Tag"
                Value="50" />
        <Setter Property="RequestedTheme"
                Value="Dark" />
    </Style>
</ResourceDictionary>