<ResourceDictionary
    xmlns="https://github.com/avaloniaui"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    x:CompileBindings="True">
    <Design.PreviewWith>
        <StackPanel Margin="20">
            <ComboBoxItem>Hello World</ComboBoxItem>
            <ComboBoxItem>Hello World</ComboBoxItem>
            <ComboBoxItem IsSelected="True">Hello World</ComboBoxItem>
            <ComboBox Width="100" SelectedIndex="0">
                <ComboBoxItem>AAA</ComboBoxItem>
                <ComboBoxItem>BBB</ComboBoxItem>
                <ComboBoxItem>CCC</ComboBoxItem>
            </ComboBox>
            <ComboBox Width="100" PlaceholderText="Select">
                <ComboBoxItem>AAA</ComboBoxItem>
                <ComboBoxItem>BBB</ComboBoxItem>
                <ComboBoxItem>CCC</ComboBoxItem>
            </ComboBox>
            <ComboBox
                Width="100"
                IsEnabled="False"
                PlaceholderText="Select">
                <ComboBoxItem>AAA</ComboBoxItem>
                <ComboBoxItem>BBB</ComboBoxItem>
                <ComboBoxItem>CCC</ComboBoxItem>
            </ComboBox>
        </StackPanel>
    </Design.PreviewWith>
    <ControlTheme x:Key="{x:Type ComboBox}" TargetType="ComboBox">
        <Setter Property="Padding" Value="{DynamicResource ComboBoxSelectorDefaultPadding}" />
        <Setter Property="FocusAdorner" Value="{x:Null}" />
        <Setter Property="MaxDropDownHeight" Value="504" />
        <Setter Property="Background" Value="{DynamicResource ComboBoxSelectorBackground}" />
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="CornerRadius" Value="{DynamicResource ComboBoxSelectorCornerRadius}" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Disabled" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Auto" />
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="HorizontalAlignment" Value="Left" />
        <Setter Property="VerticalAlignment" Value="Top" />
        <Setter Property="Template">
            <ControlTemplate TargetType="ComboBox">
                <DataValidationErrors>
                    <Grid ColumnDefinitions="*,32">
                        <Border
                            x:Name="Background"
                            Grid.Column="0"
                            Grid.ColumnSpan="2"
                            MinWidth="{DynamicResource ComboBoxThemeMinWidth}"
                            MinHeight="{DynamicResource ComboBoxDefaultHeight}"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            CornerRadius="{TemplateBinding CornerRadius}" />
                        <TextBlock
                            x:Name="PlaceholderTextBlock"
                            Grid.Column="0"
                            Margin="{TemplateBinding Padding}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            Foreground="{TemplateBinding Foreground}"
                            IsVisible="{TemplateBinding SelectionBoxItem,
                                                        Converter={x:Static ObjectConverters.IsNull}}"
                            Opacity="0.3"
                            Text="{TemplateBinding PlaceholderText}" />
                        <ContentPresenter
                            x:Name="ContentPresenter"
                            Grid.Column="0"
                            Margin="{TemplateBinding Padding}"
                            HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                            VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                            Content="{TemplateBinding SelectionBoxItem}"
                            ContentTemplate="{TemplateBinding ItemTemplate}" />

                        <Border
                            x:Name="DropDownOverlay"
                            Grid.Column="1"
                            Width="30"
                            Margin="0,1,1,1"
                            HorizontalAlignment="Right"
                            Background="Transparent"
                            IsVisible="False" />

                        <PathIcon
                            x:Name="DropDownGlyph"
                            Grid.Column="1"
                            Width="12"
                            Height="12"
                            Margin="0,0,10,0"
                            HorizontalAlignment="Right"
                            VerticalAlignment="Center"
                            Data="{DynamicResource ComboBoxIcon}"
                            Foreground="{DynamicResource ComboBoxIconDefaultForeground}"
                            IsHitTestVisible="False"
                            UseLayoutRounding="False" />

                        <Popup
                            Name="PART_Popup"
                            Grid.Column="0"
                            MinWidth="{Binding Bounds.Width, RelativeSource={RelativeSource TemplatedParent}}"
                            MaxHeight="{TemplateBinding MaxDropDownHeight}"
                            ClipToBounds="False"
                            InheritsTransform="True"
                            IsLightDismissEnabled="True"
                            IsOpen="{TemplateBinding IsDropDownOpen,
                                                     Mode=TwoWay}"
                            PlacementTarget="Background"
                            WindowManagerAddShadowHint="False">
                            <Border
                                x:Name="PopupBorder"
                                Margin="0,4"
                                HorizontalAlignment="Stretch"
                                Background="{DynamicResource ComboBoxPopupBackground}"
                                BorderBrush="{DynamicResource ComboBoxPopupBorderBrush}"
                                BorderThickness="{DynamicResource ComboBoxPopupBorderThickness}"
                                BoxShadow="{DynamicResource ComboBoxPopupBoxShadow}"
                                ClipToBounds="True"
                                CornerRadius="6">
                                <ScrollViewer HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}" VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}">
                                    <ItemsPresenter
                                        Name="PART_ItemsPresenter"
                                        Margin="{DynamicResource ComboBoxDropdownContentMargin}"
                                        ItemsPanel="{TemplateBinding ItemsPanel}" />
                                </ScrollViewer>
                            </Border>
                        </Popup>
                    </Grid>
                </DataValidationErrors>
            </ControlTemplate>
        </Setter>

        <Style Selector="^.Large /template/ Border#Background">
            <Setter Property="ComboBox.MinHeight" Value="{DynamicResource ComboBoxLargeHeight}" />
        </Style>
        <Style Selector="^.Small /template/ Border#Background">
            <Setter Property="ComboBox.MinHeight" Value="{DynamicResource ComboBoxSmallHeight}" />
        </Style>

        <!--  Pointerover State  -->
        <Style Selector="^:pointerover">
            <Setter Property="Background" Value="{DynamicResource ComboBoxSelectorPointeroverBackground}" />
            <Setter Property="BorderBrush" Value="{DynamicResource ComboBoxSelectorPointeroverBorderBrush}" />
        </Style>
        <Style Selector="^:pointerover /template/ PathIcon#DropDownGlyph">
            <Setter Property="Foreground" Value="{DynamicResource ComboBoxIconPointeroverForeground}" />
        </Style>

        <!--  Pressed State  -->
        <Style Selector="^:pressed">
            <Setter Property="Background" Value="{DynamicResource ComboBoxSelectorPressedBackground}" />
            <Setter Property="BorderBrush" Value="{DynamicResource ComboBoxSelectorPressedBorderBrush}" />
            <Style Selector="^ /template/ PathIcon#DropDownGlyph">
                <Setter Property="Foreground" Value="{DynamicResource ComboBoxIconPressedForeground}" />
            </Style>
        </Style>

        <Style Selector="^:dropdownopen">
            <Setter Property="BorderBrush" Value="{DynamicResource ComboBoxSelectorPressedBorderBrush}" />
        </Style>

        <!--  Disabled State  -->
        <Style Selector="^:disabled">
            <Setter Property="Background" Value="{DynamicResource ComboBoxSelectorDisabledBackground}" />
            <Style Selector="^ /template/ ContentControl#ContentPresenter">
                <Setter Property="Foreground" Value="{DynamicResource ComboBoxDisabledForeground}" />
            </Style>
            <Style Selector="^ /template/ TextBlock#PlaceholderTextBlock">
                <Setter Property="Foreground" Value="{DynamicResource ComboBoxDisabledForeground}" />
            </Style>
            <Style Selector="^ /template/ PathIcon#DropDownGlyph">
                <Setter Property="Foreground" Value="{DynamicResource ComboBoxIconDisabledForeground}" />
            </Style>
        </Style>
        <!--  Error State  -->
        <Style Selector="^:error">
            <Style Selector="^ /template/ Border#Background">
                <Setter Property="Background" Value="{DynamicResource DataValidationErrorsBackground}" />
            </Style>
            <Style Selector="^:pointerover /template/ Border#Background">
                <Setter Property="Background" Value="{DynamicResource DataValidationErrorsPointerOverBackground}" />
                <Setter Property="BorderBrush" Value="Transparent" />
            </Style>
            <Style Selector="^:pressed /template/ Border#Background">
                <Setter Property="Background" Value="{DynamicResource DataValidationErrorsPressedBackground}" />
                <Setter Property="BorderBrush" Value="Transparent" />
            </Style>
            <Style Selector="^:focus /template/ Border#Background">
                <Setter Property="Background" Value="{DynamicResource DataValidationErrorsSelectedBackground}" />
                <Setter Property="BorderBrush" Value="{DynamicResource DataValidationErrorsSelectedBorderBrush}" />
            </Style>
        </Style>

        <Style Selector="^.Bordered">
            <Style Selector="^ /template/ Border#Background">
                <Setter Property="Background" Value="{DynamicResource ComboBoxSelectorBorderedBackground}" />
                <Setter Property="BorderBrush" Value="{DynamicResource ComboBoxSelectorBorderedBorderBrush}" />
            </Style>
            <Style Selector="^:pointerover /template/ Border#Background">
                <Setter Property="Background" Value="{DynamicResource ComboBoxSelectorBorderedPointeroverBackground}" />
                <Setter Property="BorderBrush" Value="{DynamicResource ComboBoxSelectorBorderedPointeroverBorderBrush}" />
            </Style>
            <Style Selector="^:pressed /template/ Border#Background">
                <Setter Property="Background" Value="{DynamicResource ComboBoxSelectorBorderedPressedBackground}" />
                <Setter Property="BorderBrush" Value="{DynamicResource ComboBoxSelectorBorderedPressedBorderBrush}" />
            </Style>
            <Style Selector="^:disabled">
                <Style Selector="^ /template/ Border#Background">
                    <Setter Property="Border.Background" Value="{DynamicResource ComboBoxSelectorDisabledBackground}" />
                    <Setter Property="Border.BorderBrush" Value="{DynamicResource ComboBoxSelectorBorderBrush}" />
                </Style>
                <Style Selector="^ /template/ ContentControl#ContentPresenter">
                    <Setter Property="Foreground" Value="{DynamicResource ComboBoxDisabledForeground}" />
                </Style>
                <Style Selector="^ /template/ TextBlock#PlaceholderTextBlock">
                    <Setter Property="Foreground" Value="{DynamicResource ComboBoxDisabledForeground}" />
                </Style>
                <Style Selector="^ /template/ PathIcon#DropDownGlyph">
                    <Setter Property="Foreground" Value="{DynamicResource ComboBoxIconDisabledForeground}" />
                </Style>
            </Style>
            <Style Selector="^:error">
                <Style Selector="^ /template/ Border#Background">
                    <Setter Property="Background" Value="{DynamicResource DataValidationErrorsBackground}" />
                    <Setter Property="BorderBrush" Value="{DynamicResource DataValidationErrorsBorderBrush}" />
                </Style>
                <Style Selector="^:pointerover /template/ Border#Background">
                    <Setter Property="Background" Value="{DynamicResource DataValidationErrorsPointerOverBackground}" />
                    <Setter Property="BorderBrush" Value="{DynamicResource DataValidationErrorsPointerOverBorderBrush}" />
                </Style>
                <Style Selector="^:pressed /template/ Border#Background">
                    <Setter Property="Background" Value="{DynamicResource DataValidationErrorsPressedBackground}" />
                    <Setter Property="BorderBrush" Value="{DynamicResource DataValidationErrorsPressedBorderBrush}" />
                </Style>
                <Style Selector="^:focus /template/ Border#Background">
                    <Setter Property="Background" Value="{DynamicResource DataValidationErrorsSelectedBackground}" />
                    <Setter Property="BorderBrush" Value="{DynamicResource DataValidationErrorsSelectedBorderBrush}" />
                </Style>
            </Style>
        </Style>
    </ControlTheme>

    <ControlTheme x:Key="{x:Type ComboBoxItem}" TargetType="ComboBoxItem">
        <Setter Property="Foreground" Value="{DynamicResource ComboBoxItemForeground}" />
        <Setter Property="Background" Value="{DynamicResource ComboBoxItemBackground}" />
        <Setter Property="Padding" Value="{DynamicResource ComboBoxItemDefaultPadding}" />
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
        <Setter Property="Template">
            <ControlTemplate TargetType="ComboBoxItem">
                <ContentPresenter
                    Name="PART_ContentPresenter"
                    Padding="{TemplateBinding Padding}"
                    HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                    VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                    Background="{TemplateBinding Background}"
                    BorderBrush="{TemplateBinding BorderBrush}"
                    BorderThickness="{TemplateBinding BorderThickness}"
                    Content="{TemplateBinding Content}"
                    ContentTemplate="{TemplateBinding ContentTemplate}"
                    CornerRadius="{TemplateBinding CornerRadius}"
                    Foreground="{TemplateBinding Foreground}" />
            </ControlTemplate>
        </Setter>

        <Style Selector="^:pointerover /template/ ContentPresenter#PART_ContentPresenter">
            <Setter Property="Background" Value="{DynamicResource ComboBoxItemPointeroverBackground}" />
        </Style>

        <Style Selector="^:disabled /template/ ContentPresenter#PART_ContentPresenter">
            <Setter Property="Background" Value="{DynamicResource ComboBoxItemDisabledBackground}" />
        </Style>

        <Style Selector="^:pressed /template/ ContentPresenter#PART_ContentPresenter">
            <Setter Property="Background" Value="{DynamicResource ComboBoxItemPressedBackground}" />
        </Style>

        <Style Selector="^:selected">
            <Style Selector="^ /template/ ContentPresenter#PART_ContentPresenter">
                <Setter Property="Background" Value="{DynamicResource ComboBoxItemSelectedBackground}" />
            </Style>
            <Style Selector="^:disabled /template/ ContentPresenter#PART_ContentPresenter">
                <Setter Property="Background" Value="{DynamicResource ComboBoxItemSelectedDisabledBackground}" />
            </Style>
            <Style Selector="^:pointerover /template/ ContentPresenter#PART_ContentPresenter">
                <Setter Property="Background" Value="{DynamicResource ComboBoxItemSelectedPointeroverBackground}" />
            </Style>
        </Style>
    </ControlTheme>
</ResourceDictionary>
