<?xml version="1.0" encoding="utf-8"?>
<!-- Resource Dictionary used to store a Data Template used to 
     display message content Image.This data template will be 
     selected by the MessageContentSelector class if the message 
     content is determined to be of Image type.
     Code behind to process control events are in MessageContentImageDataTemplate.cs 
     You should include a static reference to MessageContentImageDataTemplate on the page where you plan to use
     the DataTemplate MessageContentImageDataTemplate.xaml-->
<ResourceDictionary
    x:Class="was.droidtransfer.features.messaging.ux.MessageContentImageDataTemplate"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:was.droidtransfer.features.messaging.ux"
    xmlns:data="using:was.droidtransfer.features.messaging.data"
    xmlns:converters="using:was.droidtransfer.features.messaging.converters"
    xmlns:commonConverters="using:was.droidtransfer.features.converters">
    <converters:MessageContentToIsSupportedConverter x:Key="MessageContentToIsSupportedConverter" />
    <converters:MessageContentToUnsupportedTextConverter x:Key="MessageContentToUnsupportedTextConverter" />
    <commonConverters:ByteArrayToBitmapImageConverter x:Key="ByteArrayToBitmapImageConverter" />
    <commonConverters:ValueToVisibilityConverter x:Key="ValueToVisibilityConverter" />
    <DataTemplate x:Key="MessageContentImageDataTemplate" x:DataType="data:IMessageContent">
        <Border Padding="0" Margin="0,0,0,0" CornerRadius="{ThemeResource HyperlinkFocusRectCornerRadius}" Background="Transparent">
            <Grid>
                <Grid MaxWidth="400" Visibility="{Binding Converter={StaticResource MessageContentToIsSupportedConverter}}">
                    <Grid PointerEntered="_grid_PointerEntered" PointerExited="_grid_PointerExited" MinWidth="{Binding ActualWidth, ElementName=image, Mode=OneWay}" MinHeight="{Binding ActualHeight, ElementName=image, Mode=OneWay}">
                        <Image x:Name="image" DoubleTapped="_preview_Click" Stretch="Uniform" Loaded="_image_Loaded" Unloaded="_image_Unloaded" DataContextChanged="_image_DataContextChanged">
                            <Image.ContextFlyout>
                                <MenuFlyout>
                                    <MenuFlyoutItem x:Uid="MenuFlyoutSaveToPC" Text="Save to PC" Click="_saveToPC_Click" Tag="{Binding}">
                                        <MenuFlyoutItem.Icon>
                                            <FontIcon Glyph="&#xE78C;"/>
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                    <MenuFlyoutItem x:Uid="MenuFlyoutPreview" Text="Preview" Click="_preview_Click" Tag="{Binding}">
                                        <MenuFlyoutItem.Icon>
                                            <FontIcon Glyph="&#xE890;"/>
                                        </MenuFlyoutItem.Icon>
                                    </MenuFlyoutItem>
                                </MenuFlyout>
                            </Image.ContextFlyout>
                        </Image>
                        <Border x:Name="borderControls" Visibility="Collapsed" HorizontalAlignment="Right" VerticalAlignment="Top" Background="{ThemeResource TextFillColorInverse}" Padding="3" Margin="5" CornerRadius="6">
                            <StackPanel Orientation="Horizontal">
                                <Button Click="_saveToPCButton_Click" BorderThickness="0" Background="Transparent" CornerRadius="4,0,0,4" Foreground="{ThemeResource TextFillColorPrimary}">
                                    <FontIcon Glyph="&#xE78C;" />
                                    <ToolTipService.ToolTip>
                                        <ToolTip x:Uid="SaveToPCToolTip" Content="Save to PC" />
                                    </ToolTipService.ToolTip>
                                </Button>
                                <AppBarSeparator />
                                <Button Click="_previewButton_Click" BorderThickness="0" Background="Transparent" CornerRadius="0,4,4,0" Foreground="{ThemeResource TextFillColorPrimary}">
                                    <FontIcon Glyph="&#xE890;" />
                                    <ToolTipService.ToolTip>
                                        <ToolTip x:Uid="PreviewToolTip" Content="Preview" />
                                    </ToolTipService.ToolTip>
                                </Button>
                            </StackPanel>
                        </Border>
                    </Grid>
                    <Border x:Name="borderPlaceholder" Background="#FF000000" Visibility="{Binding Source, ElementName=image, Converter={StaticResource ValueToVisibilityConverter}, ConverterParameter='invert'}" Height="250" VerticalAlignment="Top" Width="400" Loaded="_borderPlaceholder_Loaded" Unloaded="_borderPlaceholder_Unloaded">
                    </Border>
                </Grid>
                <Border BorderThickness="4,0,0,0" BorderBrush="{ThemeResource SystemErrorTextColor}" HorizontalAlignment="Stretch" Padding="8,2,4,8" Background="{ThemeResource TextFillColorInverse}" CornerRadius="0,4,4,0" Visibility="{Binding Converter={StaticResource MessageContentToIsSupportedConverter}, ConverterParameter='invert'}" Margin="0,0,0,4">
                    <StackPanel Spacing="5">
                        <TextBlock Style="{ThemeResource BodyStrongTextBlockStyle}" Text="{Binding Converter={StaticResource MessageContentToUnsupportedTextConverter}}" Padding="0" Margin="0" Foreground="{ThemeResource SystemErrorTextColor}" />
                        <TextBlock x:Uid="TextBlockUnsupportedImageDescription" TextWrapping="Wrap" Text="XX This image format cannot be previewed but can be saved to your PC." Padding="0" Margin="0" />
                        <Button x:Uid="ButtonUnsupportedSaveToPC" Margin="0,10,0,0" Content="XX Save to PC" Click="_saveToPCButton_Click" />
                    </StackPanel>
                </Border>
            </Grid>
        </Border>
    </DataTemplate>
</ResourceDictionary>
