<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="using:Microsoft.Toolkit.Uwp.UI.Controls">

    <Style TargetType="controls:ImageEx">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Foreground" Value="{ThemeResource ApplicationForegroundThemeBrush}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:ImageEx">
                    <Grid Background="{TemplateBinding Background}" CornerRadius="{TemplateBinding CornerRadius}">
                        <Image Name="PlaceholderImage"
                               HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                               VerticalAlignment="{TemplateBinding VerticalAlignment}"
                               Opacity="1.0"
                               Source="{TemplateBinding PlaceholderSource}"
                               Stretch="{TemplateBinding PlaceholderStretch}" />
                        <Image Name="Image"
                               HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
                               VerticalAlignment="{TemplateBinding VerticalAlignment}"
                               NineGrid="{TemplateBinding NineGrid}"
                               Opacity="0.0"
                               Stretch="{TemplateBinding Stretch}" />
                        <ProgressRing Name="Progress"
                                      Margin="16"
                                      HorizontalAlignment="Center"
                                      VerticalAlignment="Center"
                                      Background="Transparent"
                                      Foreground="{TemplateBinding Foreground}"
                                      IsActive="False"
                                      Visibility="Collapsed" />
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Failed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Image"
                                                                       Storyboard.TargetProperty="Opacity">
                                            <DiscreteObjectKeyFrame KeyTime="0"
                                                                    Value="0" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderImage"
                                                                       Storyboard.TargetProperty="Opacity">
                                            <DiscreteObjectKeyFrame KeyTime="0"
                                                                    Value="1" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Loading">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Progress"
                                                                       Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0"
                                                                    Value="Visible" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Progress"
                                                                       Storyboard.TargetProperty="IsActive">
                                            <DiscreteObjectKeyFrame KeyTime="0"
                                                                    Value="True" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Image"
                                                                       Storyboard.TargetProperty="Opacity">
                                            <DiscreteObjectKeyFrame KeyTime="0"
                                                                    Value="0" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderImage"
                                                                       Storyboard.TargetProperty="Opacity">
                                            <DiscreteObjectKeyFrame KeyTime="0"
                                                                    Value="1" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Loaded">
                                    <Storyboard>
                                        <DoubleAnimation AutoReverse="False"
                                                         BeginTime="0"
                                                         Storyboard.TargetName="Image"
                                                         Storyboard.TargetProperty="Opacity"
                                                         From="0"
                                                         To="1" />
                                        <DoubleAnimation AutoReverse="False"
                                                         BeginTime="0"
                                                         Storyboard.TargetName="PlaceholderImage"
                                                         Storyboard.TargetProperty="Opacity"
                                                         From="1"
                                                         To="0" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Unloaded" />
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
