<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:ghfvs="https://github.com/github/VisualStudio">

    <PathGeometry x:Key="arrow">M 0,6 3.5,11 7,6</PathGeometry>

    <ControlTemplate x:Key="ComboBoxTemplate" TargetType="{x:Type ghfvs:GitHubComboBox}">
        <Grid x:Name="MainGrid" SnapsToDevicePixels="true"
              MinWidth="{Binding ActualWidth, ElementName=PART_Popup}"
              Background="{TemplateBinding Background}">
            <Popup x:Name="PART_Popup" 
                   AllowsTransparency="true" 
                   Grid.ColumnSpan="2" 
                   MaxHeight="300"
                   IsOpen="{Binding IsDropDownOpen, RelativeSource={RelativeSource TemplatedParent}}" 
                   Margin="1"
                   PlacementTarget="{Binding ElementName=MainGrid}"
                   Placement="Custom">
                <Border x:Name="dropDownBorder"
                        BorderBrush="#CBCBCB"
                        BorderThickness="1"
                        Background="{TemplateBinding Background}">
                    <ScrollViewer CanContentScroll="true">
                        <ItemsPresenter KeyboardNavigation.DirectionalNavigation="Contained" 
                                    SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                    </ScrollViewer>
                </Border>
            </Popup>
            <ghfvs:OcticonLinkToggleButton
                x:Name="toggleButton"
                Focusable="True"
                FocusVisualStyle="{DynamicResource NegativeMarginFocusVisual}"
                PathChecked="{StaticResource arrow}"
                PathUnchecked="{StaticResource arrow}"
                ContentTemplate="{TemplateBinding SelectionBoxItemTemplate}" 
                ContentTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                Content="{TemplateBinding SelectionBoxItem}" 
                ContentStringFormat="{TemplateBinding SelectionBoxItemStringFormat}"
                FontSize="12"
                IconWidth="7"
                Margin="{TemplateBinding Padding}"
                HorizontalContentAlignment="Left"
                BorderBrush="{TemplateBinding BorderBrush}"
                BorderThickness="{TemplateBinding BorderThickness}"
                Background="Transparent"
                IsChecked="{Binding IsDropDownOpen, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
            </ghfvs:OcticonLinkToggleButton>
        </Grid>
        <ControlTemplate.Triggers>
            <Trigger Property="HasDropShadow" SourceName="PART_Popup" Value="true">
                <Setter Property="Margin" Value="1"/>
                <!--<Setter Property="Color" TargetName="shadow" Value="#f0f0f0"/>-->
            </Trigger>
            <Trigger Property="HasItems" Value="false">
                <Setter Property="Height" TargetName="dropDownBorder" Value="95"/>
            </Trigger>
            <Trigger Property="IsGrouping" Value="true">
                <Setter Property="ScrollViewer.CanContentScroll" Value="false"/>
            </Trigger>
        </ControlTemplate.Triggers>
        
    </ControlTemplate>
    <ghfvs:IsLastItemInContainerConverter x:Key="IsLastItemInContainerConverter" />

    <Style x:Key="GitHubComboBoxItem" TargetType="{x:Type ComboBoxItem}">
        <Setter Property="Foreground" Value="{DynamicResource GHTextBrush}"/>
        <Setter Property="Background" Value="{Binding Background, RelativeSource={RelativeSource AncestorType={x:Type ItemsControl}}}"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ComboBoxItem}">
                    <Border x:Name="itemSeparator" BorderThickness="0,0,0,1" BorderBrush="{DynamicResource GHBoxDividerBrush}" Padding="5">
                        <Grid x:Name="templateRoot" Background="{TemplateBinding Background}">
                            <ContentPresenter SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" Height="20" Margin="0,0,50,0" />
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Converter={StaticResource IsLastItemInContainerConverter}}" Value="true">
                            <Setter Property="BorderThickness" Value="0" TargetName="itemSeparator"/>
                        </DataTrigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="itemSeparator" Property="Background" Value="{DynamicResource GHBoxHoverBackgroundBrush}"/>
                            <Setter TargetName="templateRoot" Property="Background" Value="{DynamicResource GHBoxHoverBackgroundBrush}"/>
                        </Trigger>
                        </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="GitHubComboBox" TargetType="{x:Type ghfvs:GitHubComboBox}">
        <Setter Property="Background" Value="White"/>
        <Setter Property="BorderBrush" Value="{DynamicResource GHBoxDividerBrush}"/>
        <Setter Property="Foreground" Value="{DynamicResource GHBlueLinkButtonTextBrush}"/>
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Auto"/>
        <Setter Property="Padding" Value="0" />
        <Setter Property="IsEditable" Value="false"/>
        <Setter Property="IsReadOnly" Value="true" />
        <Setter Property="Focusable" Value="False" />
        <Setter Property="Template" Value="{StaticResource ComboBoxTemplate}"/>
        <Setter Property="ItemContainerStyle" Value="{StaticResource GitHubComboBoxItem}" />
    </Style>

</ResourceDictionary>