<UserControl x:Class="GitHub.VisualStudio.UI.Controls.AccountAvatar"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:local="clr-namespace:GitHub.VisualStudio.UI.Controls"
             Name="root"
             MinWidth="16" MinHeight="16">
    <Button Command="{Binding Command, ElementName=root}"
            CommandParameter="{Binding CommandParameter, ElementName=root}"
            CommandTarget="{Binding CommandTarget, ElementName=root}"
            MinWidth="0">
        <Button.Template>
            <ControlTemplate TargetType="Button">
                <ContentPresenter/>
            </ControlTemplate>
        </Button.Template>
        <Grid>
            <Grid.OpacityMask>
                <VisualBrush Visual="{Binding ElementName=avatarMask}"/>
            </Grid.OpacityMask>
            <Border Name="avatarMask" Background="White" CornerRadius="3"
                Width="{Binding ActualWidth, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:AccountAvatar}}}"
                Height="{Binding ActualHeight, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:AccountAvatar}}}"/>
            <Image x:Name="avatar"
               Width="{Binding Width, ElementName=avatarMask}"
               Height="{Binding Height, ElementName=avatarMask}"
               RenderOptions.BitmapScalingMode="HighQuality"
               Source="{Binding Account.Avatar, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:AccountAvatar}}}" />
        </Grid>
    </Button>
</UserControl>
