<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Controls="clr-namespace:MahApps.Metro.Controls">

    <ControlTemplate x:Key="SplitButtonHorizontal" TargetType="{x:Type Controls:SplitButton}">
        <Grid UseLayoutRounding="True">
            <Border x:Name="PART_Border"
                    Background="Transparent"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    CornerRadius="{TemplateBinding Controls:ControlsHelper.CornerRadius}"
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                <Controls:ClipBorder x:Name="PART_ClipBorder"
                                     CornerRadius="{TemplateBinding Controls:ControlsHelper.CornerRadius}"
                                     SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                    <Grid x:Name="PART_Container"
                          HorizontalAlignment="Stretch"
                          VerticalAlignment="Stretch">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <Button x:Name="PART_Button"
                                Grid.Column="0"
                                HorizontalAlignment="Stretch"
                                VerticalAlignment="Stretch"
                                HorizontalContentAlignment="Stretch"
                                VerticalContentAlignment="Stretch"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                Command="{TemplateBinding Command}"
                                CommandParameter="{TemplateBinding CommandParameter}"
                                CommandTarget="{TemplateBinding CommandTarget}"
                                FocusVisualStyle="{TemplateBinding FocusVisualStyle}"
                                Foreground="{TemplateBinding Foreground}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                Style="{TemplateBinding ButtonStyle}">
                            <StackPanel HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                        Orientation="Horizontal">
                                <ContentPresenter HorizontalAlignment="Center"
                                                  VerticalAlignment="Center"
                                                  Content="{TemplateBinding Icon}"
                                                  ContentTemplate="{TemplateBinding IconTemplate}"
                                                  Focusable="False"
                                                  RecognizesAccessKey="True"
                                                  UseLayoutRounding="False" />
                                <Controls:ContentControlEx x:Name="PART_ButtonContent"
                                                           Margin="2"
                                                           Padding="{TemplateBinding Padding}"
                                                           HorizontalAlignment="Center"
                                                           VerticalAlignment="Center"
                                                           HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                           VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                                           Content="{Binding SelectedItem, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                                           ContentCharacterCasing="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.ContentCharacterCasing)}"
                                                           ContentStringFormat="{TemplateBinding ItemStringFormat}"
                                                           ContentTemplate="{TemplateBinding ItemTemplate}"
                                                           ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                                                           RecognizesAccessKey="True"
                                                           SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                                           UseLayoutRounding="False" />
                            </StackPanel>
                        </Button>
                        <Button x:Name="PART_Expander"
                                Grid.Column="1"
                                Width="20"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                FocusVisualStyle="{TemplateBinding FocusVisualStyle}"
                                Foreground="{TemplateBinding ArrowBrush}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                Style="{TemplateBinding ButtonArrowStyle}">
                            <!--  Material - ChevronDown  -->
                            <ContentControl Width="9"
                                            Height="9"
                                            Content="M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z"
                                            Style="{DynamicResource PathIconContentControlStyle}" />
                        </Button>
                    </Grid>
                </Controls:ClipBorder>
            </Border>
            <Popup x:Name="PART_Popup"
                   AllowsTransparency="True"
                   Focusable="False"
                   IsOpen="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                   PlacementTarget="{Binding ElementName=PART_Border}"
                   PopupAnimation="Fade"
                   StaysOpen="True">
                <ListBox x:Name="PART_ListBox"
                         MinWidth="{Binding ActualWidth, RelativeSource={RelativeSource TemplatedParent}}"
                         Margin="0"
                         BorderBrush="{TemplateBinding BorderBrush}"
                         BorderThickness="{TemplateBinding BorderThickness}"
                         DisplayMemberPath="{TemplateBinding DisplayMemberPath}"
                         IsSelected="{TemplateBinding IsSelected}"
                         IsSynchronizedWithCurrentItem="{TemplateBinding IsSynchronizedWithCurrentItem}"
                         ItemContainerStyle="{TemplateBinding ItemContainerStyle}"
                         ItemContainerStyleSelector="{TemplateBinding ItemContainerStyleSelector}"
                         ItemStringFormat="{TemplateBinding ItemStringFormat}"
                         ItemTemplate="{TemplateBinding ItemTemplate}"
                         ItemTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                         ItemsPanel="{TemplateBinding ItemsPanel}"
                         ItemsSource="{TemplateBinding ItemsSource}"
                         RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}"
                         SelectedIndex="{Binding SelectedIndex, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                         SelectedItem="{Binding SelectedItem, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                         SelectedValue="{Binding SelectedValue, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                         SelectedValuePath="{TemplateBinding SelectedValuePath}"
                         SelectionMode="Single"
                         SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                         Style="{TemplateBinding ListBoxStyle}" />
            </Popup>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter TargetName="PART_Expander" Property="Foreground" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ArrowMouseOverBrush, Mode=OneWay}" />
            </Trigger>
            <Trigger SourceName="PART_Expander" Property="IsPressed" Value="True">
                <Setter TargetName="PART_Expander" Property="Foreground" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ArrowPressedBrush, Mode=OneWay}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <ControlTemplate x:Key="SplitButtonVertical" TargetType="{x:Type Controls:SplitButton}">
        <Grid UseLayoutRounding="True">
            <Border x:Name="PART_Border"
                    Background="Transparent"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    CornerRadius="{TemplateBinding Controls:ControlsHelper.CornerRadius}"
                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                <Controls:ClipBorder x:Name="PART_ClipBorder"
                                     CornerRadius="{TemplateBinding Controls:ControlsHelper.CornerRadius}"
                                     SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                    <Grid x:Name="PART_Container"
                          HorizontalAlignment="Stretch"
                          VerticalAlignment="Stretch">
                        <Grid.RowDefinitions>
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Button x:Name="PART_Button"
                                Grid.Row="0"
                                HorizontalAlignment="Stretch"
                                VerticalAlignment="Stretch"
                                HorizontalContentAlignment="Stretch"
                                VerticalContentAlignment="Stretch"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                Command="{TemplateBinding Command}"
                                CommandParameter="{TemplateBinding CommandParameter}"
                                CommandTarget="{TemplateBinding CommandTarget}"
                                FocusVisualStyle="{TemplateBinding FocusVisualStyle}"
                                Foreground="{TemplateBinding Foreground}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                Style="{TemplateBinding ButtonStyle}">
                            <StackPanel HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                        VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                        Orientation="Vertical">
                                <ContentPresenter HorizontalAlignment="Center"
                                                  VerticalAlignment="Center"
                                                  Content="{TemplateBinding Icon}"
                                                  ContentTemplate="{TemplateBinding IconTemplate}"
                                                  Focusable="False"
                                                  RecognizesAccessKey="True"
                                                  UseLayoutRounding="False" />
                                <Controls:ContentControlEx x:Name="PART_ButtonContent"
                                                           Margin="2"
                                                           Padding="{TemplateBinding Padding}"
                                                           HorizontalAlignment="Center"
                                                           VerticalAlignment="Center"
                                                           HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                           VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                                                           Content="{Binding SelectedItem, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                                                           ContentCharacterCasing="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.ContentCharacterCasing)}"
                                                           ContentStringFormat="{TemplateBinding ItemStringFormat}"
                                                           ContentTemplate="{TemplateBinding ItemTemplate}"
                                                           ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                                                           RecognizesAccessKey="True"
                                                           SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                                           UseLayoutRounding="False" />
                            </StackPanel>
                        </Button>
                        <Button x:Name="PART_Expander"
                                Grid.Row="1"
                                Height="20"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                FocusVisualStyle="{TemplateBinding FocusVisualStyle}"
                                Foreground="{TemplateBinding ArrowBrush}"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                Style="{TemplateBinding ButtonArrowStyle}">
                            <!--  Material - ChevronDown  -->
                            <ContentControl Width="9"
                                            Height="9"
                                            Content="M7.41,8.58L12,13.17L16.59,8.58L18,10L12,16L6,10L7.41,8.58Z"
                                            Style="{DynamicResource PathIconContentControlStyle}" />
                        </Button>
                    </Grid>
                </Controls:ClipBorder>
            </Border>
            <Popup x:Name="PART_Popup"
                   AllowsTransparency="True"
                   Focusable="False"
                   IsOpen="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                   PlacementTarget="{Binding ElementName=PART_Border}"
                   PopupAnimation="Fade"
                   StaysOpen="True">
                <ListBox x:Name="PART_ListBox"
                         MinWidth="{Binding ActualWidth, RelativeSource={RelativeSource TemplatedParent}}"
                         Margin="0"
                         BorderBrush="{TemplateBinding BorderBrush}"
                         BorderThickness="{TemplateBinding BorderThickness}"
                         DisplayMemberPath="{TemplateBinding DisplayMemberPath}"
                         IsSelected="{TemplateBinding IsSelected}"
                         IsSynchronizedWithCurrentItem="{TemplateBinding IsSynchronizedWithCurrentItem}"
                         ItemContainerStyle="{TemplateBinding ItemContainerStyle}"
                         ItemContainerStyleSelector="{TemplateBinding ItemContainerStyleSelector}"
                         ItemStringFormat="{TemplateBinding ItemStringFormat}"
                         ItemTemplate="{TemplateBinding ItemTemplate}"
                         ItemTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                         ItemsPanel="{TemplateBinding ItemsPanel}"
                         ItemsSource="{TemplateBinding ItemsSource}"
                         RenderOptions.ClearTypeHint="{TemplateBinding RenderOptions.ClearTypeHint}"
                         SelectedIndex="{Binding SelectedIndex, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                         SelectedItem="{Binding SelectedItem, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                         SelectedValue="{Binding SelectedValue, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}"
                         SelectedValuePath="{TemplateBinding SelectedValuePath}"
                         SelectionMode="Single"
                         SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                         Style="{TemplateBinding ListBoxStyle}" />
            </Popup>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="IsMouseOver" Value="True">
                <Setter TargetName="PART_Expander" Property="Foreground" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ArrowMouseOverBrush, Mode=OneWay}" />
            </Trigger>
            <Trigger SourceName="PART_Expander" Property="IsPressed" Value="True">
                <Setter TargetName="PART_Expander" Property="Foreground" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ArrowPressedBrush, Mode=OneWay}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style x:Key="ButtonSplitFocusVisual">
        <Setter Property="Control.Template">
            <Setter.Value>
                <ControlTemplate>
                    <Rectangle Margin="1"
                               SnapsToDevicePixels="true"
                               Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}"
                               StrokeDashArray="1 2"
                               StrokeThickness="1" />
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type Controls:SplitButton}">
        <Setter Property="ArrowBrush" Value="{DynamicResource BlackColorBrush}" />
        <Setter Property="ArrowMouseOverBrush" Value="{DynamicResource AccentColorBrush}" />
        <Setter Property="ArrowPressedBrush" Value="{DynamicResource BlackColorBrush}" />
        <Setter Property="Background" Value="{DynamicResource WhiteColorBrush}" />
        <Setter Property="BorderBrush" Value="{DynamicResource BlackColorBrush}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="ButtonArrowStyle" Value="{DynamicResource ButtonSplitArrowStyle}" />
        <Setter Property="ButtonStyle" Value="{DynamicResource ButtonSplitStyle}" />
        <Setter Property="FocusVisualStyle" Value="{StaticResource ButtonSplitFocusVisual}" />
        <Setter Property="Focusable" Value="False" />
        <Setter Property="FontFamily" Value="{DynamicResource ContentFontFamily}" />
        <Setter Property="FontSize" Value="{DynamicResource ContentFontSize}" />
        <Setter Property="Foreground" Value="{DynamicResource BlackColorBrush}" />
        <Setter Property="HorizontalContentAlignment" Value="Center" />
        <Setter Property="ListBoxStyle" Value="{DynamicResource VirtualisedMetroListBox}" />
        <Setter Property="MinHeight" Value="26" />
        <Setter Property="RenderOptions.ClearTypeHint" Value="Enabled" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="Template" Value="{StaticResource SplitButtonHorizontal}" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Style.Triggers>
            <Trigger Property="Orientation" Value="Vertical">
                <Setter Property="Template" Value="{StaticResource SplitButtonVertical}" />
            </Trigger>
            <Trigger Property="IsFocused" Value="True">
                <Setter Property="BorderBrush" Value="{DynamicResource AccentColorBrush}" />
            </Trigger>
            <Trigger Property="IsKeyboardFocusWithin" Value="True">
                <Setter Property="BorderBrush" Value="{DynamicResource AccentColorBrush}" />
            </Trigger>
            <Trigger Property="IsEnabled" Value="False">
                <Setter Property="Opacity" Value=".55" />
            </Trigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>