<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:RoundImageEx">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Foreground" Value="{ThemeResource ApplicationForegroundThemeBrush}" />
        <Setter Property="HorizontalAlignment" Value="Stretch" />
        <Setter Property="VerticalAlignment" Value="Stretch" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="controls:RoundImageEx">
                    <Grid Width="{TemplateBinding Width}"
                          Height="{TemplateBinding Height}">
                        <Rectangle x:Name="PlaceholderRectangle"
                                   HorizontalAlignment="Stretch"
                                   VerticalAlignment="Stretch"
                                   Opacity="1.0"
                                   RadiusX="{TemplateBinding CornerRadius}"
                                   RadiusY="{TemplateBinding CornerRadius}"
                                   Stroke="{TemplateBinding BorderBrush}"
                                   StrokeThickness="{TemplateBinding BorderThickness}">
                            <Rectangle.Fill>
                                <ImageBrush x:Name="PlaceholderImage"
                                            ImageSource="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=PlaceholderSource}"
                                            Stretch="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=PlaceholderStretch}" />
                            </Rectangle.Fill>
                        </Rectangle>
                        <Rectangle x:Name="ImageRectangle"
                                   HorizontalAlignment="Stretch"
                                   VerticalAlignment="Stretch"
                                   Opacity="0.0"
                                   RadiusX="{TemplateBinding CornerRadius}"
                                   RadiusY="{TemplateBinding CornerRadius}"
                                   Stroke="{TemplateBinding BorderBrush}"
                                   StrokeThickness="{TemplateBinding BorderThickness}">
                            <Rectangle.Fill>
                                <ImageBrush x:Name="Image"
                                            Stretch="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Stretch}" />
                            </Rectangle.Fill>
                        </Rectangle>
                        <ProgressRing Name="Progress"
                                      Margin="16"
                                      HorizontalAlignment="Center"
                                      VerticalAlignment="Center"
                                      Background="Transparent"
                                      Foreground="{TemplateBinding Foreground}"
                                      IsActive="False" />

                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Failed">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ImageRectangle"
                                                                       Storyboard.TargetProperty="Opacity">
                                            <DiscreteObjectKeyFrame KeyTime="0"
                                                                    Value="0" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderRectangle"
                                                                       Storyboard.TargetProperty="Opacity">
                                            <DiscreteObjectKeyFrame KeyTime="0"
                                                                    Value="1" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Loading">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Progress"
                                                                       Storyboard.TargetProperty="IsActive">
                                            <DiscreteObjectKeyFrame KeyTime="0"
                                                                    Value="True" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="ImageRectangle"
                                                                       Storyboard.TargetProperty="Opacity">
                                            <DiscreteObjectKeyFrame KeyTime="0"
                                                                    Value="0" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="PlaceholderRectangle"
                                                                       Storyboard.TargetProperty="Opacity">
                                            <DiscreteObjectKeyFrame KeyTime="0"
                                                                    Value="1" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Loaded">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="Progress"
                                                                       Storyboard.TargetProperty="IsActive">
                                            <DiscreteObjectKeyFrame KeyTime="0"
                                                                    Value="False" />
                                        </ObjectAnimationUsingKeyFrames>
                                        <DoubleAnimation AutoReverse="False"
                                                         BeginTime="0"
                                                         Storyboard.TargetName="ImageRectangle"
                                                         Storyboard.TargetProperty="Opacity"
                                                         From="0"
                                                         To="1" />
                                        <DoubleAnimation AutoReverse="False"
                                                         BeginTime="0"
                                                         Storyboard.TargetName="PlaceholderRectangle"
                                                         Storyboard.TargetProperty="Opacity"
                                                         From="1"
                                                         To="0" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Unloaded" />
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
