<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:Petzold.ProgrammingWindows6.Chapter11">

    <Style TargetType="local:NewToggle">
        <Setter Property="BorderBrush" Value="{StaticResource ApplicationForegroundThemeBrush}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:NewToggle">
                    <Border Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}">

                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="CheckStates">
                                <VisualState x:Name="Unchecked" />
                                
                                <VisualState x:Name="Checked">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames 
                                                Storyboard.TargetName="UncheckButton"
                                                Storyboard.TargetProperty="BorderThickness">
                                            <DiscreteObjectKeyFrame KeyTime="0"
                                                                    Value="0" />
                                        </ObjectAnimationUsingKeyFrames>

                                        <ObjectAnimationUsingKeyFrames 
                                                Storyboard.TargetName="CheckButton"
                                                Storyboard.TargetProperty="BorderThickness">
                                            <DiscreteObjectKeyFrame KeyTime="0"
                                                                    Value="8" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>

                        <local:UniformGrid Rows="1">
                            <Button Name="UncheckButton"
                                    Content="{TemplateBinding Content}"
                                    ContentTemplate="{TemplateBinding ContentTemplate}"
                                    FontSize="{TemplateBinding FontSize}"
                                    BorderBrush="Red"
                                    BorderThickness="8"
                                    HorizontalAlignment="Stretch" />
                            
                            <Button Name="CheckButton"
                                    Content="{TemplateBinding CheckedContent}"
                                    ContentTemplate="{TemplateBinding ContentTemplate}"
                                    FontSize="{TemplateBinding FontSize}"
                                    BorderBrush="Green"
                                    BorderThickness="0"
                                    HorizontalAlignment="Stretch" />
                        </local:UniformGrid>
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

