<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:GitHub.UI">

    <Style x:Key="OcticonLinkToggleButton" TargetType="{x:Type local:OcticonLinkToggleButton}">
        <Setter Property="Background" Value="Transparent"/>
        <Setter Property="Foreground" Value="{DynamicResource GHBlueLinkButtonTextBrush}"/>
        <Setter Property="FocusVisualStyle" Value="{DynamicResource NegativeMarginFocusVisual}"/>

        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="Padding" Value="0"/>
        <Setter Property="FontSize" Value="14"/>

        <Setter Property="HorizontalContentAlignment" Value="Right"/>
        <Setter Property="VerticalContentAlignment" Value="Center"/>
        
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">

                    <Grid Background="Transparent" IsHitTestVisible="True" HorizontalAlignment="Left" Margin="{TemplateBinding Padding}">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>

                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CommonStates">
                                <VisualState x:Name="Normal">
                                    <Storyboard>
                                        <ColorAnimation To="{DynamicResource GHTextColor}" Duration="0" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="checked" />
                                        <ColorAnimation To="{DynamicResource GHTextColor}" Duration="0" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="unchecked" />
                                        <ColorAnimation To="{DynamicResource GHTextColor}" Duration="0" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="indeterminate" />
                                        <ColorAnimation To="{DynamicResource GHTextColor}" Duration="0" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="contentPresenter" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="MouseOver">
                                    <Storyboard>
                                        <ColorAnimation To="{DynamicResource GHBlueLinkButtonHoverIconColor}" Duration="0" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="checked" />
                                        <ColorAnimation To="{DynamicResource GHBlueLinkButtonHoverIconColor}" Duration="0" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="unchecked" />
                                        <ColorAnimation To="{DynamicResource GHBlueLinkButtonHoverIconColor}" Duration="0" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="indeterminate" />
                                        <ColorAnimation To="{DynamicResource GHBlueLinkButtonHoverColor}" Duration="0" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="contentPresenter" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Pressed">
                                    <Storyboard>
                                        <ColorAnimation To="{DynamicResource GHBlueLinkButtonPressedIconColor}" Duration="0" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="checked" />
                                        <ColorAnimation To="{DynamicResource GHBlueLinkButtonPressedIconColor}" Duration="0" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="unchecked" />
                                        <ColorAnimation To="{DynamicResource GHBlueLinkButtonPressedIconColor}" Duration="0" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="indeterminate" />
                                        <ColorAnimation To="{DynamicResource GHBlueLinkButtonPressedColor}" Duration="0" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="contentPresenter" />
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Disabled">
                                    <Storyboard>
                                        <ColorAnimation To="{DynamicResource GHTextColor}" Duration="0" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="checked" />
                                        <ColorAnimation To="{DynamicResource GHTextColor}" Duration="0" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="unchecked" />
                                        <ColorAnimation To="{DynamicResource GHTextColor}" Duration="0" Storyboard.TargetProperty="(Shape.Fill).(SolidColorBrush.Color)" Storyboard.TargetName="indeterminate" />
                                        <ColorAnimation To="{DynamicResource GHTextColor}" Duration="0" Storyboard.TargetProperty="(TextBlock.Foreground).(SolidColorBrush.Color)" Storyboard.TargetName="contentPresenter" />

                                        <DoubleAnimation To="0.3" Duration="0" Storyboard.TargetProperty="Opacity" />
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                            <VisualStateGroup x:Name="CheckStates">
                                <VisualState x:Name="Checked">
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="checked">
                                            <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Unchecked">
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="unchecked">
                                            <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="Indeterminate">
                                    <Storyboard>
                                        <DoubleAnimationUsingKeyFrames Storyboard.TargetProperty="(UIElement.Opacity)" Storyboard.TargetName="indeterminate">
                                            <EasingDoubleKeyFrame KeyTime="0" Value="1"/>
                                        </DoubleAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>

                        <Grid x:Name="iconGrid" 
                              UseLayoutRounding="True" 
                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                            <Grid.Resources>
                                <Style TargetType="{x:Type Viewbox}">
                                    <Setter Property="Height" Value="{Binding Path=(local:OcticonLinkToggleButton.IconHeight), RelativeSource={RelativeSource TemplatedParent}, FallbackValue=16.0}" />
                                    <Setter Property="Width" Value="{Binding Path=(local:OcticonLinkToggleButton.IconWidth), RelativeSource={RelativeSource TemplatedParent}, FallbackValue=16.0}" />
                                    <Setter Property="UseLayoutRounding" Value="True" />
                                </Style>

                                <Style TargetType="{x:Type Path}">
                                    <Setter Property="Height" Value="16" />
                                    <Setter Property="Fill" Value="#666" />
                                    <Setter Property="Opacity" Value="0" />
                                </Style>

                            </Grid.Resources>

                            <Viewbox>
                                <Path x:Name="checked" RenderTransformOrigin="0.5,0.5" Data="{Binding Path=(local:OcticonToggleButton.PathChecked), RelativeSource={RelativeSource TemplatedParent}}" >
                                    <Path.RenderTransform>
                                        <RotateTransform Angle="{Binding Path=(local:OcticonToggleButton.IconRotationAngle), RelativeSource={RelativeSource TemplatedParent}}" />
                                    </Path.RenderTransform>
                                </Path>
                            </Viewbox>

                            <Viewbox>
                                <Path x:Name="unchecked" RenderTransformOrigin="0.5,0.5" Data="{Binding Path=(local:OcticonToggleButton.PathUnchecked), RelativeSource={RelativeSource TemplatedParent}}">
                                    <Path.RenderTransform>
                                        <RotateTransform Angle="{Binding Path=(local:OcticonToggleButton.IconRotationAngle), RelativeSource={RelativeSource TemplatedParent}}" />
                                    </Path.RenderTransform>
                                </Path>
                            </Viewbox>

                            <Viewbox>
                                <Path x:Name="indeterminate" RenderTransformOrigin="0.5,0.5" Data="{Binding Path=(local:OcticonToggleButton.PathIndeterminate), RelativeSource={RelativeSource TemplatedParent}}">
                                    <Path.RenderTransform>
                                        <RotateTransform Angle="{Binding Path=(local:OcticonToggleButton.IconRotationAngle), RelativeSource={RelativeSource TemplatedParent}}" />
                                    </Path.RenderTransform>
                                </Path>
                            </Viewbox>

                        </Grid>

                        <ContentPresenter 
                            x:Name="contentPresenter" 
                            IsHitTestVisible="False"
                            Grid.Column="1"
                            Focusable="False"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" 
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            RecognizesAccessKey="True" 
                            ContentTemplate="{TemplateBinding ContentTemplate}" 
                            ContentTemplateSelector="{TemplateBinding ContentTemplateSelector}"
                            Content="{TemplateBinding Content}" 
                            ContentStringFormat="{TemplateBinding ContentStringFormat}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                            <TextBlock.Foreground>
                                <SolidColorBrush Color="{DynamicResource GHBlueLinkButtonIconColor}" />
                            </TextBlock.Foreground>
                            <ContentPresenter.Style>
                                <Style TargetType="{x:Type ContentPresenter}">
                                    <Style.Triggers>
                                        <Trigger Property="Content" Value="{x:Null}">
                                            <Setter Property="Visibility" Value="Collapsed" />
                                        </Trigger>
                                    </Style.Triggers>
                                </Style>
                            </ContentPresenter.Style>
                        </ContentPresenter>

                    </Grid>

                    <ControlTemplate.Triggers>
                        <Trigger Property="HorizontalContentAlignment" Value="Left">
                            <Setter Property="Grid.Column" Value="0" TargetName="contentPresenter" />
                            <Setter Property="Grid.Column" Value="1" TargetName="iconGrid" />
                            <Setter Property="Margin" Value="0,0,3,0" TargetName="contentPresenter" />
                        </Trigger>
                        <Trigger Property="HorizontalContentAlignment" Value="Right">
                            <Setter Property="Grid.Column" Value="1" TargetName="contentPresenter" />
                            <Setter Property="Grid.Column" Value="0" TargetName="iconGrid" />
                            <Setter Property="Margin" Value="3,0,0,0" TargetName="contentPresenter" />
                        </Trigger>
                        <Trigger Property="HorizontalContentAlignment" Value="Center">
                            <Setter Property="Grid.Column" Value="0" TargetName="contentPresenter" />
                            <Setter Property="Grid.Column" Value="0" TargetName="iconGrid" />
                        </Trigger>
                    </ControlTemplate.Triggers>

                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style BasedOn="{StaticResource OcticonLinkToggleButton}" TargetType="{x:Type local:OcticonLinkToggleButton}" />

</ResourceDictionary>