<!-- 
This template provides default visualisation of the nullable image  RSS data produced by 
the Shared:CharmNullableImageSource shared spark control. It is intended to be used in 
conjuction with the sc:ResultContentControl XAML control:
    
<sc:ResultContentControl Tag="UniformToFill"
                         Content="{Binding}"
                         DataContext="{Binding Extended:pagePreview}" />    
    
Tag attribute of the related sc:ResultContentControl should contain a value of the 
Windows.UI.Xaml.Media.Stretch enum that is used to set a value of the image's Stretch property.         
-->
    
<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="Shared.NullableImagePlaceholder_8_1_RP">
					
    <ControlTemplate x:Key="Local.ImageTemplate" TargetType="ContentControl">
        <Grid Style="{CustomResource Resources.Shared.ImagePlaceholderGridStyle}">
            <Image Stretch="{Binding Tag, RelativeSource={RelativeSource TemplatedParent}}"			       				   
                   Source="{Binding Extended:image.Extended:src}"
                   AutomationProperties.AutomationId="NullableImage"
                   ToolTipService.ToolTip="{Binding Extended:image.Extended:alt}"
                   Style="{CustomResource Resources.Shared.BaseImageStyle}" />
			<Rectangle Style="{CustomResource Resources.Shared.ImagePlaceholderRectangleStyle}" />
		</Grid>
    </ControlTemplate>

    <ControlTemplate x:Key="Local.FallbackTemplate" TargetType="ContentControl">
        <Border Style="{CustomResource Resources.Shared.ImagePlaceholderBorderStyle}">
            <TextBlock tm:RichText.Text="{Binding Extended:image.Extended:fallbackMessage}"
                       Style="{CustomResource Resources.Shared.SerpSecondaryTextStyle}"
                       VerticalAlignment="Center"
                       HorizontalAlignment="Center"
			           AutomationProperties.AutomationId="NullableImageFallbackText" />
        </Border> 
    </ControlTemplate>

    <tm:SwitchCaseConverter x:Key="Local.TemplateSelector" Default="{StaticResource Local.FallbackTemplate}">
        <tm:SwitchCase Case="true" Value="{StaticResource Local.ImageTemplate}" />
    </tm:SwitchCaseConverter>

    <Style x:Key="Horizontal" TargetType="ContentControl">        
        <Setter Property="tm:SetterBinding.Setters">
            <Setter.Value>
                <SetterBaseCollection>
                    <Setter Property="Template">
                        <Setter.Value>
                            <tm:SetterBinding Path="Extended:image.Extended:imageAvailable" 
							                  Converter="{StaticResource Local.TemplateSelector}" />
                        </Setter.Value>
                    </Setter>
                </SetterBaseCollection>
            </Setter.Value>
        </Setter>		
    </Style>	
</ResourceDictionary>