<ResourceDictionary
    xmlns="https://github.com/avaloniaui"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:CompileBindings="True">
    <Design.PreviewWith>
        <StackPanel Margin="20">
            <ToggleSwitch
                Content="Content"
                OffContent="OffContent"
                OnContent="OnContent" />
        </StackPanel>
    </Design.PreviewWith>
    <ControlTheme x:Key="{x:Type ToggleSwitch}" TargetType="ToggleSwitch">
        <Setter Property="HorizontalAlignment" Value="Left" />
        <Setter Property="VerticalAlignment" Value="Center" />
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Template">
            <ControlTemplate TargetType="ToggleSwitch">
                <Grid
                    Background="{TemplateBinding Background}"
                    Cursor="Hand"
                    RowDefinitions="Auto,*">
                    <ContentPresenter
                        x:Name="PART_ContentPresenter"
                        Grid.Row="0"
                        Margin="{DynamicResource ToggleSwitchHeaderMargin}"
                        VerticalAlignment="Top"
                        Content="{TemplateBinding Content}"
                        ContentTemplate="{TemplateBinding ContentTemplate}"
                        IsVisible="{TemplateBinding Content,
                                                    Converter={x:Static ObjectConverters.IsNotNull}}"
                        RecognizesAccessKey="True" />
                    <Grid
                        Grid.Row="1"
                        Background="Transparent"
                        ColumnDefinitions="Auto, *">
                        <Grid
                            Grid.Column="0"
                            Grid.ColumnSpan="2"
                            TemplatedControl.IsTemplateFocusTarget="True" />
                        <Border
                            Name="SwitchBackgroundBorder"
                            Grid.Column="0"
                            Width="40"
                            Height="20"
                            CornerRadius="100">
                            <Border.Transitions>
                                <Transitions>
                                    <BrushTransition Property="Background" Duration="0:0:0.2" />
                                </Transitions>
                            </Border.Transitions>
                        </Border>
                        <Canvas
                            x:Name="PART_SwitchKnob"
                            Grid.Column="0"
                            Width="20"
                            Height="20"
                            HorizontalAlignment="Left">
                            <Grid
                                x:Name="PART_MovingKnobs"
                                Width="20"
                                Height="20">
                                <Border
                                    x:Name="SwitchKnobIndicator"
                                    Width="14"
                                    Height="14"
                                    Background="White"
                                    BorderBrush="{DynamicResource ToggleSwitchIndicatorBorderBrush}"
                                    BorderThickness="0.5"
                                    BoxShadow="0 0 1 1 #222E3238"
                                    CornerRadius="100" />
                            </Grid>
                        </Canvas>

                        <ContentPresenter
                            x:Name="PART_OnContentPresenter"
                            Grid.Column="1"
                            Margin="{DynamicResource ToggleSwitchOnContentMargin}"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            VerticalContentAlignment="Center"
                            Content="{TemplateBinding OnContent}"
                            ContentTemplate="{TemplateBinding OnContentTemplate}"
                            IsVisible="True" />
                        <ContentPresenter
                            x:Name="PART_OffContentPresenter"
                            Grid.Column="1"
                            Margin="{DynamicResource ToggleSwitchOnContentMargin}"
                            HorizontalAlignment="Left"
                            VerticalAlignment="Center"
                            VerticalContentAlignment="Center"
                            Content="{TemplateBinding OffContent}"
                            ContentTemplate="{TemplateBinding OffContentTemplate}"
                            IsVisible="False" />

                    </Grid>
                </Grid>
            </ControlTemplate>
        </Setter>

        <Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter:empty">
            <Setter Property="Margin" Value="0" />
        </Style>

        <!--  NormalState  -->
        <Style Selector="^:not(:dragging) /template/ Grid#PART_MovingKnobs">
            <Setter Property="Transitions">
                <Transitions>
                    <DoubleTransition
                        Easing="CubicEaseOut"
                        Property="Canvas.Left"
                        Duration="0:0:0.2" />
                </Transitions>
            </Setter>
        </Style>

        <Style Selector="^:unchecked">
            <Style Selector="^ /template/ ContentPresenter#PART_OnContentPresenter">
                <Setter Property="ContentPresenter.IsVisible" Value="False" />
            </Style>
            <Style Selector="^ /template/ ContentPresenter#PART_OffContentPresenter">
                <Setter Property="ContentPresenter.IsVisible" Value="True" />
            </Style>
            <Style Selector="^ /template/ Border#SwitchBackgroundBorder">
                <Setter Property="Border.Background" Value="{DynamicResource ToggleSwitchContainerUnCheckedDefaultBackground}" />
            </Style>
            <Style Selector="^:pointerover /template/ Border#SwitchBackgroundBorder">
                <Setter Property="Border.Background" Value="{DynamicResource ToggleSwitchContainerUnCheckedPointeroverBackground}" />
            </Style>
            <Style Selector="^:pressed /template/ Border#SwitchBackgroundBorder">
                <Setter Property="Border.Background" Value="{DynamicResource ToggleSwitchContainerUnCheckedPressedBackground}" />
            </Style>
            <Style Selector="^:disabled /template/ Border#SwitchBackgroundBorder">
                <Setter Property="Border.Background" Value="{DynamicResource ToggleSwitchContainerUnCheckedDisabledBackground}" />
                <Setter Property="Border.BorderBrush" Value="{DynamicResource ToggleSwitchContainerUnCheckedDisabledBorderBrush}" />
                <Setter Property="Border.BorderThickness" Value="1" />
            </Style>
        </Style>

        <Style Selector="^:checked">
            <Style Selector="^ /template/ ContentPresenter#PART_OnContentPresenter">
                <Setter Property="ContentPresenter.IsVisible" Value="True" />
            </Style>
            <Style Selector="^ /template/ ContentPresenter#PART_OffContentPresenter">
                <Setter Property="ContentPresenter.IsVisible" Value="False" />
            </Style>
            <Style Selector="^ /template/ Border#SwitchBackgroundBorder">
                <Setter Property="Border.Background" Value="{DynamicResource ToggleSwitchContainerCheckedDefaultBackground}" />
            </Style>
            <Style Selector="^:pointerover /template/ Border#SwitchBackgroundBorder">
                <Setter Property="Border.Background" Value="{DynamicResource ToggleSwitchContainerCheckedPointeroverBackground}" />
            </Style>
            <Style Selector="^:pressed /template/ Border#SwitchBackgroundBorder">
                <Setter Property="Border.Background" Value="{DynamicResource ToggleSwitchContainerCheckedPressedBackground}" />
            </Style>
            <Style Selector="^:disabled /template/ Border#SwitchBackgroundBorder">
                <Setter Property="Border.Background" Value="{DynamicResource ToggleSwitchContainerCheckedDisabledBackground}" />
            </Style>
        </Style>
    </ControlTheme>

    <ControlTheme
        x:Key="ButtonToggleSwitch"
        BasedOn="{StaticResource {x:Type ToggleSwitch}}"
        TargetType="ToggleSwitch">
        <Setter Property="Padding" Value="8" />
        <Setter Property="CornerRadius" Value="3" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Template">
            <ControlTemplate TargetType="ToggleSwitch">
                <Border
                    Name="Background"
                    Padding="{TemplateBinding Padding}"
                    Background="{TemplateBinding Background}"
                    CornerRadius="{TemplateBinding CornerRadius}"
                    Cursor="Hand">
                    <Grid ColumnDefinitions="Auto">
                        <Grid x:Name="PART_SwitchKnob" />
                        <Grid x:Name="PART_MovingKnobs" />
                        <ContentPresenter
                            x:Name="PART_OnContentPresenter"
                            Margin="{DynamicResource ToggleSwitchOnContentMargin}"
                            Content="{TemplateBinding OnContent}"
                            ContentTemplate="{TemplateBinding OnContentTemplate}" />
                        <ContentPresenter
                            x:Name="PART_OffContentPresenter"
                            Margin="{DynamicResource ToggleSwitchOnContentMargin}"
                            Content="{TemplateBinding OffContent}"
                            ContentTemplate="{TemplateBinding OffContentTemplate}" />
                    </Grid>
                </Border>
            </ControlTemplate>
        </Setter>
        <Style Selector="^:pointerover">
            <Setter Property="Background" Value="{DynamicResource ButtonDefaultPointeroverBackground}" />
        </Style>
        <Style Selector="^:pressed">
            <Setter Property="Background" Value="{DynamicResource ButtonDefaultPressedBackground}" />
        </Style>
    </ControlTheme>

    <ControlTheme
        x:Key="SimpleToggleSwitch"
        BasedOn="{StaticResource {x:Type ToggleSwitch}}"
        TargetType="ToggleSwitch">
        <Setter Property="Template">
            <ControlTemplate TargetType="ToggleSwitch">
                <Grid
                    Background="{TemplateBinding Background}"
                    Cursor="Hand"
                    RowDefinitions="*">
                    <Grid
                        Grid.Row="0"
                        Background="Transparent"
                        ColumnDefinitions="Auto, *">
                        <Grid
                            Grid.Column="0"
                            Grid.ColumnSpan="2"
                            TemplatedControl.IsTemplateFocusTarget="True" />
                        <Border
                            Name="SwitchBackgroundBorder"
                            Grid.Column="0"
                            Width="40"
                            Height="20"
                            CornerRadius="100">
                            <Border.Transitions>
                                <Transitions>
                                    <BrushTransition Property="Background" Duration="0:0:0.2" />
                                </Transitions>
                            </Border.Transitions>
                        </Border>
                        <Canvas
                            x:Name="PART_SwitchKnob"
                            Grid.Column="0"
                            Width="20"
                            Height="20"
                            HorizontalAlignment="Left">
                            <Grid
                                x:Name="PART_MovingKnobs"
                                Width="20"
                                Height="20">
                                <Border
                                    x:Name="SwitchKnobIndicator"
                                    Width="14"
                                    Height="14"
                                    Background="White"
                                    BorderBrush="{DynamicResource ToggleSwitchIndicatorBorderBrush}"
                                    BorderThickness="0.5"
                                    BoxShadow="0 0 1 1 #222E3238"
                                    CornerRadius="100" />
                            </Grid>
                        </Canvas>
                    </Grid>
                </Grid>
            </ControlTemplate>
        </Setter>
    </ControlTheme>
</ResourceDictionary>