<UserControl x:Class="ControlExplorer.Controls.ListBox.ListBoxSample"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d"
    xmlns:local="using:ControlExplorer.Controls.ListBox"
    xmlns:c1="using:C1.Xaml"
    d:DesignHeight="480" d:DesignWidth="480">

    <Grid x:Name="LayoutRoot">
        <StackPanel x:Name="loading" VerticalAlignment="Center">
            <TextBlock Text="Retrieving data from Flickr..." TextAlignment="Center" Style="{ThemeResource BaseTextBlockStyle}"/>
            <c1:C1ProgressBar IsIndeterminate="True" Height="Auto" IndeterminateForeground="#FF2C383D"/>
        </StackPanel>
        <Button x:Name="retry" HorizontalAlignment="Center" VerticalAlignment="Center" Content="Retry" Visibility="Collapsed" Click="Retry_Click"/>
        <c1:C1ListViewer x:Name="listBox" 
                         ItemsSource="{Binding}" 
                         Background="Transparent"
                         Foreground="White"
                         Visibility="Collapsed"
                         ItemWidth="800"
                         ItemHeight="600"
                         ViewportGap="0"
                         RefreshWhileScrolling="False"
                         HorizontalContentAlignment="Stretch"
                         VerticalContentAlignment="Stretch"
                         ItemTapped="OnItemTapped">
            <c1:C1ListViewer.PreviewItemTemplate>
                <DataTemplate>
                    <Grid Background="Gray">
                        <Image Source="{Binding Thumbnail}" Stretch="UniformToFill"/>
                    </Grid>
                </DataTemplate>
            </c1:C1ListViewer.PreviewItemTemplate>
            <c1:C1ListViewer.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Image Source="{Binding Content}" Stretch="UniformToFill"/>
                        <TextBlock Text="{Binding Title}" Foreground="White" Margin="4 0 0 4" VerticalAlignment="Bottom" Style="{ThemeResource BaseTextBlockStyle}"/>
                    </Grid>
                </DataTemplate>
            </c1:C1ListViewer.ItemTemplate>
            <c1:C1ListViewer.ItemStyle>
                <!--This style allows showing the preview while the full image is being loaded-->
                <Style TargetType="c1:C1ListViewerItem">
                    <Setter Property="BorderThickness" Value="8"/>
                    <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
                    <Setter Property="VerticalContentAlignment" Value="Stretch"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="c1:C1ListViewerItem">
                                <Border BorderBrush="{TemplateBinding BorderBrush}" 
                            BorderThickness="{TemplateBinding BorderThickness}" 
                            Background="{TemplateBinding Background}">
                                    <VisualStateManager.VisualStateGroups>
                                        <VisualStateGroup x:Name="CommonStates">
                                            <VisualState x:Name="Normal"/>
                                            <VisualState x:Name="PointerOver"/>
                                            <VisualState x:Name="Disabled">
                                                <Storyboard>
                                                    <DoubleAnimation Duration="0" To=".55" Storyboard.TargetProperty="Opacity" Storyboard.TargetName="Content"/>
                                                </Storyboard>
                                            </VisualState>
                                        </VisualStateGroup>
                                        <VisualStateGroup x:Name="PreviewStates">
                                            <VisualState x:Name="Full">
                                                <Storyboard>
                                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="(UIElement.Visibility)">
                                                        <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                            <DiscreteObjectKeyFrame.Value>
                                                                <Visibility>Visible</Visibility>
                                                            </DiscreteObjectKeyFrame.Value>
                                                        </DiscreteObjectKeyFrame>
                                                    </ObjectAnimationUsingKeyFrames>
                                                </Storyboard>
                                            </VisualState>
                                            <VisualState x:Name="Preview">
                                                <Storyboard>
                                                    <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Content" Storyboard.TargetProperty="(UIElement.Visibility)">
                                                        <DiscreteObjectKeyFrame KeyTime="00:00:00">
                                                            <DiscreteObjectKeyFrame.Value>
                                                                <Visibility>Collapsed</Visibility>
                                                            </DiscreteObjectKeyFrame.Value>
                                                        </DiscreteObjectKeyFrame>
                                                    </ObjectAnimationUsingKeyFrames>
                                                </Storyboard>
                                            </VisualState>
                                        </VisualStateGroup>
                                    </VisualStateManager.VisualStateGroups>
                                    <Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                        <ContentControl x:Name="PreviewElement" 
                                            Content="{TemplateBinding PreviewContent}" 
                                            ContentTemplate="{TemplateBinding PreviewContentTemplate}" 
                                            Visibility="Visible"
                                            HorizontalContentAlignment="Stretch"
                                            VerticalContentAlignment="Stretch"/>
                                        <ContentPresenter x:Name="Content" Visibility="Collapsed"/>
                                    </Grid>
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                </Style>
            </c1:C1ListViewer.ItemStyle>
        </c1:C1ListViewer>
    </Grid>
</UserControl>
