<Styles xmlns="https://github.com/avaloniaui"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        x:CompileBindings="True"
        xmlns:converters="using:Avalonia.Controls.Converters">

  <Design.PreviewWith>
    <Border Padding="60">
      <StackPanel>
        <SplitButton Content="Hello World">
          <SplitButton.Flyout>
            <Flyout>Hello</Flyout>
          </SplitButton.Flyout>
        </SplitButton>
        <ToggleSplitButton Content="Hello World">
          <ToggleSplitButton.Flyout>
            <Flyout>Hello</Flyout>
          </ToggleSplitButton.Flyout>
        </ToggleSplitButton>
      </StackPanel>
    </Border>
  </Design.PreviewWith>

  <Styles.Resources>
    <x:Double x:Key="SplitButtonPrimaryButtonSize">32</x:Double>
    <x:Double x:Key="SplitButtonSecondaryButtonSize">32</x:Double>
    <x:Double x:Key="SplitButtonSeparatorWidth">1</x:Double>
    <x:Double x:Key="SplitButtonMinHeight">32</x:Double>

    <converters:MarginMultiplierConverter x:Key="PrimaryButtonBorderMultiplier" Left="True" Top="True" Bottom="True" Indent="1" />
    <converters:MarginMultiplierConverter x:Key="SecondaryButtonBorderMultiplier" Right="True" Top="True" Bottom="True" Indent="1" />
    <converters:MarginMultiplierConverter x:Key="SeparatorBorderMultiplier" Top="True" Bottom="True" Indent="1" />
  </Styles.Resources>

  <Style Selector="SplitButton">
    <Setter Property="Background" Value="{DynamicResource SplitButtonBackground}" />
    <Setter Property="Foreground" Value="{DynamicResource SplitButtonForeground}" />
    <Setter Property="BorderBrush" Value="{DynamicResource SplitButtonBorderBrush}" />
    <Setter Property="BorderThickness" Value="{DynamicResource SplitButtonBorderThemeThickness}" />
    <Setter Property="MinHeight" Value="{DynamicResource SplitButtonMinHeight}" />
    <Setter Property="HorizontalAlignment" Value="Left" />
    <Setter Property="VerticalAlignment" Value="Center" />
    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    <Setter Property="VerticalContentAlignment" Value="Center" />
    <!--<Setter Property="UseSystemFocusVisuals" Value="True" />
    <Setter Property="FocusVisualMargin" Value="-3" />-->
    <Setter Property="KeyboardNavigation.IsTabStop" Value="True" />
    <Setter Property="Focusable" Value="True" />
    <Setter Property="Padding" Value="{DynamicResource ButtonPadding}" />
    <Setter Property="CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
    <Setter Property="Template">
      <Setter.Value>
        <ControlTemplate>
          <Grid>
            <Grid.ColumnDefinitions>
              <ColumnDefinition Width="*" />
              <ColumnDefinition Width="Auto" />
              <ColumnDefinition Width="Auto" />
            </Grid.ColumnDefinitions>

            <Button x:Name="PART_PrimaryButton"
                    Grid.Column="0"
                    MinWidth="{DynamicResource SplitButtonPrimaryButtonSize}"
                    Foreground="{TemplateBinding Foreground}"
                    Background="{TemplateBinding Background}"
                    BorderThickness="{TemplateBinding BorderThickness, Converter={StaticResource PrimaryButtonBorderMultiplier}}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    Content="{TemplateBinding Content}"
                    ContentTemplate="{TemplateBinding ContentTemplate}"
                    Command="{TemplateBinding Command}"
                    CommandParameter="{TemplateBinding CommandParameter}"
                    FontFamily="{TemplateBinding FontFamily}"
                    FontSize="{TemplateBinding FontSize}"
                    FontWeight="{TemplateBinding FontWeight}"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Stretch"
                    HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                    VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                    Padding="{TemplateBinding Padding}"
                    Focusable="False"
                    KeyboardNavigation.IsTabStop="False" />

            <Border x:Name="SeparatorBorder"
                    Grid.Column="1"
                    Background="Transparent"
                    Width="{DynamicResource SplitButtonSeparatorWidth}"
                    BorderThickness="{TemplateBinding BorderThickness, Converter={StaticResource SeparatorBorderMultiplier}}"
                    BorderBrush="{TemplateBinding BorderBrush}" />

            <Button x:Name="PART_SecondaryButton"
                    Grid.Column="2"
                    MinWidth="{DynamicResource SplitButtonSecondaryButtonSize}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    Foreground="{TemplateBinding Foreground}"
                    Background="{TemplateBinding Background}"
                    BorderThickness="{TemplateBinding BorderThickness, Converter={StaticResource SecondaryButtonBorderMultiplier}}"
                    Padding="0"
                    HorizontalContentAlignment="Center"
                    VerticalContentAlignment="Center"
                    HorizontalAlignment="Stretch"
                    VerticalAlignment="Stretch"
                    Focusable="False"
                    KeyboardNavigation.IsTabStop="False" />
          </Grid>
        </ControlTemplate>
      </Setter.Value>
    </Setter>
  </Style>

  <!-- Default overridable styles -->
  <Style Selector="SplitButton /template/ Button#PART_PrimaryButton">
    <Setter Property="CornerRadius" Value="{TemplateBinding CornerRadius, Converter={StaticResource LeftCornerRadiusFilterConverter}}" />
  </Style>
  <Style Selector="SplitButton /template/ Button#PART_SecondaryButton">
    <Setter Property="CornerRadius" Value="{TemplateBinding CornerRadius, Converter={StaticResource RightCornerRadiusFilterConverter}}" />
    <Setter Property="Content">
      <Template>
        <PathIcon Height="12"
                  Width="12"
                  Data="M1939 486L2029 576L1024 1581L19 576L109 486L1024 1401L1939 486Z" />
      </Template>
    </Setter>
  </Style>

  <!-- Primary and Secondary buttons PointerOver State -->
  <Style Selector="SplitButton /template/ Button#PART_PrimaryButton:pointerover /template/ ContentPresenter,
         SplitButton /template/ Button#PART_SecondaryButton:pointerover /template/ ContentPresenter">
    <Setter Property="Border.Background" Value="{DynamicResource SplitButtonBackgroundPointerOver}" />
    <Setter Property="Border.BorderBrush" Value="{DynamicResource SplitButtonBorderBrushPointerOver}" />
    <Setter Property="Foreground" Value="{DynamicResource SplitButtonForegroundPointerOver}" />
  </Style>
  <Style Selector="SplitButton /template/ Button#PART_SecondaryButton:pointerover PathIcon">
    <Setter Property="Foreground" Value="{DynamicResource SplitButtonForegroundPointerOver}" />
  </Style>

  <!-- Primary and Secondary buttons Pressed State -->
  <Style Selector="SplitButton /template/ Button#PART_PrimaryButton:pressed /template/ ContentPresenter,
         SplitButton /template/ Button#PART_SecondaryButton:pressed /template/ ContentPresenter">
    <Setter Property="Border.Background" Value="{DynamicResource SplitButtonBackgroundPressed}" />
    <Setter Property="Border.BorderBrush" Value="{DynamicResource SplitButtonBorderBrushPressed}" />
    <Setter Property="Foreground" Value="{DynamicResource SplitButtonForegroundPressed}" />
  </Style>
  <Style Selector="SplitButton /template/ Button#PART_SecondaryButton:pressed PathIcon">
    <Setter Property="Foreground" Value="{DynamicResource SplitButtonForegroundPressed}" />
  </Style>

  <!-- SplitButton Pressed State -->
  <Style Selector="SplitButton:pressed /template/ Button#PART_PrimaryButton /template/ ContentPresenter,
         SplitButton:pressed /template/ Button#PART_SecondaryButton /template/ ContentPresenter,
         SplitButton:pressed /template/ Border#SeparatorBorder">
    <Setter Property="Border.Background" Value="{DynamicResource SplitButtonBackgroundPressed}" />
    <Setter Property="Border.BorderBrush" Value="{DynamicResource SplitButtonBorderBrushPressed}" />
    <Setter Property="TextElement.Foreground" Value="{DynamicResource SplitButtonForegroundPressed}" />
  </Style>
  <Style Selector="SplitButton:pressed /template/ Button#PART_SecondaryButton PathIcon">
    <Setter Property="Foreground" Value="{DynamicResource SplitButtonForegroundPressed}" />
  </Style>

  <!-- Primary and Secondary buttons Flyout Open State -->
  <Style Selector="SplitButton:flyout-open /template/ Button#PART_PrimaryButton /template/ ContentPresenter,
         SplitButton:flyout-open /template/ Button#PART_SecondaryButton /template/ ContentPresenter,
         SplitButton:flyout-open /template/ Border#SeparatorBorder">
    <Setter Property="Border.Background" Value="{DynamicResource SplitButtonBackgroundPressed}" />
    <Setter Property="Border.BorderBrush" Value="{DynamicResource SplitButtonBorderBrushPressed}" />
    <Setter Property="TextElement.Foreground" Value="{DynamicResource SplitButtonForegroundPressed}" />
  </Style>
  <Style Selector="SplitButton:flyout-open /template/ Button#PART_SecondaryButton PathIcon">
    <Setter Property="Foreground" Value="{DynamicResource SplitButtonForegroundPressed}" />
  </Style>

  <!-- Disabled State -->
  <Style Selector="SplitButton:disabled /template/ Button#PART_PrimaryButton /template/ ContentPresenter,
         SplitButton:disabled /template/ Button#PART_SecondaryButton /template/ ContentPresenter,
         SplitButton:disabled /template/ Border#SeparatorBorder">
    <Setter Property="Border.Background" Value="{DynamicResource SplitButtonBackgroundDisabled}" />
    <Setter Property="Border.BorderBrush" Value="{DynamicResource SplitButtonBorderBrushDisabled}" />
    <Setter Property="TextElement.Foreground" Value="{DynamicResource SplitButtonForegroundDisabled}" />
  </Style>
  <Style Selector="SplitButton:disabled /template/ Button#PART_SecondaryButton PathIcon">
    <Setter Property="Foreground" Value="{DynamicResource SplitButtonForegroundDisabled}" />
  </Style>

  <!-- Checked State -->
  <Style Selector="SplitButton:checked /template/ Button#PART_PrimaryButton /template/ ContentPresenter,
         SplitButton:checked /template/ Button#PART_SecondaryButton /template/ ContentPresenter,
         SplitButton:checked /template/ Border#SeparatorBorder">
    <Setter Property="Border.Background" Value="{DynamicResource SplitButtonBackgroundChecked}" />
    <Setter Property="Border.BorderBrush" Value="{DynamicResource SplitButtonBorderBrushChecked}" />
    <Setter Property="TextElement.Foreground" Value="{DynamicResource SplitButtonForegroundChecked}" />
  </Style>
  <Style Selector="SplitButton:checked /template/ Button#PART_SecondaryButton PathIcon">
    <Setter Property="Foreground" Value="{DynamicResource SplitButtonForegroundChecked}" />
  </Style>

  <!-- Checked PointerOver State -->
  <Style Selector="SplitButton:checked /template/ Button#PART_PrimaryButton:pointerover /template/ ContentPresenter,
         SplitButton:checked /template/ Button#PART_SecondaryButton:pointerover /template/ ContentPresenter">
    <Setter Property="Border.Background" Value="{DynamicResource SplitButtonBackgroundCheckedPointerOver}" />
    <Setter Property="Border.BorderBrush" Value="{DynamicResource SplitButtonBorderBrushCheckedPointerOver}" />
    <Setter Property="TextElement.Foreground" Value="{DynamicResource SplitButtonForegroundCheckedPointerOver}" />
  </Style>
  <Style Selector="SplitButton:checked /template/ Button#PART_SecondaryButton:pointerover PathIcon">
    <Setter Property="Foreground" Value="{DynamicResource SplitButtonForegroundCheckedPointerOver}" />
  </Style>

  <!-- Checked Pressed State -->
  <Style Selector="SplitButton:checked /template/ Button#PART_PrimaryButton:pressed /template/ ContentPresenter,
         SplitButton:checked /template/ Button#PART_SecondaryButton:pressed /template/ ContentPresenter">
    <Setter Property="Border.Background" Value="{DynamicResource SplitButtonBackgroundCheckedPressed}" />
    <Setter Property="Border.BorderBrush" Value="{DynamicResource SplitButtonBorderBrushCheckedPressed}" />
    <Setter Property="Foreground" Value="{DynamicResource SplitButtonForegroundCheckedPressed}" />
  </Style>
  <Style Selector="SplitButton:checked /template/ Button#PART_SecondaryButton:pressed PathIcon">
    <Setter Property="Foreground" Value="{DynamicResource SplitButtonForegroundCheckedPressed}" />
  </Style>

  <!-- SplitButton Checked Pressed State -->
  <Style Selector="SplitButton:pressed:checked /template/ Button#PART_PrimaryButton /template/ ContentPresenter,
         SplitButton:pressed:checked /template/ Button#PART_SecondaryButton /template/ ContentPresenter,
         SplitButton:pressed:checked /template/ Border#SeparatorBorder">
    <Setter Property="Border.Background" Value="{DynamicResource SplitButtonBackgroundCheckedPressed}" />
    <Setter Property="Border.BorderBrush" Value="{DynamicResource SplitButtonBorderBrushCheckedPressed}" />
    <Setter Property="TextElement.Foreground" Value="{DynamicResource SplitButtonForegroundCheckedPressed}" />
  </Style>
  <Style Selector="SplitButton:pressed:checked /template/ Button#PART_SecondaryButton PathIcon">
    <Setter Property="Foreground" Value="{DynamicResource SplitButtonForegroundCheckedPressed}" />
  </Style>

  <!-- Checked Flyout Open State -->
  <Style Selector="SplitButton:checked:flyout-open /template/ Button#PART_PrimaryButton /template/ ContentPresenter,
         SplitButton:checked:flyout-open /template/ Button#PART_SecondaryButton /template/ ContentPresenter,
         SplitButton:checked:flyout-open /template/ Border#SeparatorBorder">
    <Setter Property="Border.Background" Value="{DynamicResource SplitButtonBackgroundCheckedPressed}" />
    <Setter Property="Border.BorderBrush" Value="{DynamicResource SplitButtonBorderBrushCheckedPressed}" />
    <Setter Property="TextElement.Foreground" Value="{DynamicResource SplitButtonForegroundCheckedPressed}" />
  </Style>
  <Style Selector="SplitButton:checked:flyout-open /template/ Button#PART_SecondaryButton PathIcon">
    <Setter Property="Foreground" Value="{DynamicResource SplitButtonForegroundCheckedPressed}" />
  </Style>

  <!-- Disabled Checked State -->
  <Style Selector="SplitButton:checked:disabled /template/ Button#PART_PrimaryButton /template/ ContentPresenter,
         SplitButton:checked:disabled /template/ Button#PART_SecondaryButton /template/ ContentPresenter,
         SplitButton:checked:disabled /template/ Border#SeparatorBorder">
    <Setter Property="Border.Background" Value="{DynamicResource SplitButtonBackgroundCheckedDisabled}" />
    <Setter Property="Border.BorderBrush" Value="{DynamicResource SplitButtonBorderBrushCheckedDisabled}" />
    <Setter Property="TextElement.Foreground" Value="{DynamicResource SplitButtonForegroundCheckedDisabled}" />
  </Style>
  <Style Selector="SplitButton:checked:disabled /template/ Button#PART_SecondaryButton PathIcon">
    <Setter Property="Foreground" Value="{DynamicResource SplitButtonForegroundCheckedDisabled}" />
  </Style>
</Styles>
