<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:editors="clr-namespace:AutoCompleteTextBox.Editors">

    <BooleanToVisibilityConverter x:Key="BoolToVisConverter" />

    <Style x:Key="TextBoxSuggestionItemStyle" TargetType="ListBoxItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <Border x:Name="ContentBorder" Background="{Binding Path=SuggestionBackground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=editors:AutoCompleteTextBox}, Mode=OneWay}">
                        <ContentPresenter />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="IsSelected" Value="True" />
                        </Trigger>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="ContentBorder" Property="Background" Value="{x:Static SystemColors.HighlightBrush}" />
                            <Setter Property="TextElement.Foreground" Value="{x:Static SystemColors.HighlightTextBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="ComboBoxSuggestionItemStyle" TargetType="ListBoxItem">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="ListBoxItem">
                    <Border x:Name="ContentBorder" Background="{Binding Path=SuggestionBackground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=editors:AutoCompleteComboBox}, Mode=OneWay}">
                        <ContentPresenter />
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="IsSelected" Value="True" />
                        </Trigger>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter TargetName="ContentBorder" Property="Background" Value="{x:Static SystemColors.HighlightBrush}" />
                            <Setter Property="TextElement.Foreground" Value="{x:Static SystemColors.HighlightTextBrush}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="TransparentTextBoxStyle" TargetType="{x:Type TextBox}">
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TextBox}">
                    <Grid>
                        <ScrollViewer
                            x:Name="PART_ContentHost"
                            Background="Transparent"
                            CanContentScroll="True"
                            Focusable="True"
                            HorizontalScrollBarVisibility="Hidden"
                            VerticalScrollBarVisibility="Hidden" />
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="{x:Type editors:AutoCompleteTextBox}">
        <Setter Property="BorderThickness" Value="1" />
        <Setter Property="BorderBrush" Value="#FFABADB3" />
        <Setter Property="SuggestionBackground" Value="White" />
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="VerticalContentAlignment" Value="Top" />
        <Setter Property="AllowDrop" Value="true" />
        <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst" />
        <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
        <Setter Property="Validation.ErrorTemplate" Value="{x:Null}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type editors:AutoCompleteTextBox}">
                    <Border
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}"
                        CornerRadius="0">
                        <Grid>
                            <DockPanel>
                                <ContentPresenter
                                    x:Name="PART_Icon"
                                    ContentSource="Icon"
                                    Visibility="{TemplateBinding IconVisibility}" />
                                <Grid>
                                    <TextBlock
                                        x:Name="PART_Watermark"
                                        Margin="3,0"
                                        HorizontalAlignment="Left"
                                        VerticalAlignment="Center"
                                        Focusable="False"
                                        Foreground="Gray"
                                        Text="{TemplateBinding Watermark}"
                                        Visibility="Collapsed" />
                                    <TextBox
                                        x:Name="PART_Editor"
                                        HorizontalAlignment="Stretch"
                                        VerticalAlignment="Center"
                                        CharacterCasing="{Binding Path=CharacterCasing, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay}"
                                        Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=OneWay}"
                                        MaxLength="{Binding Path=MaxLength, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay}"
                                        Style="{StaticResource ResourceKey=TransparentTextBoxStyle}" />
                                </Grid>
                            </DockPanel>
                            <Popup
                                x:Name="PART_Popup"
                                MinWidth="{TemplateBinding ActualWidth}"
                                MinHeight="25"
                                MaxHeight="600"
                                AllowsTransparency="True"
                                Focusable="False"
                                HorizontalOffset="0"
                                IsOpen="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay}"
                                PopupAnimation="Slide">
                                <Border
                                    Padding="2"
                                    Background="{Binding Path=SuggestionBackground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=editors:AutoCompleteTextBox}, Mode=OneWay}"
                                    BorderBrush="Gray"
                                    BorderThickness="1"
                                    CornerRadius="5">
                                    <Grid Background="{Binding Path=SuggestionBackground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=editors:AutoCompleteTextBox}, Mode=OneWay}">
                                        <ListBox
                                            x:Name="PART_Selector"
                                            MaxWidth="{Binding Path=MaxPopupWidth, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay}"
                                            MaxHeight="{Binding Path=MaxPopupHeight, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay}"
                                            Background="{Binding Path=SuggestionBackground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=editors:AutoCompleteTextBox}, Mode=OneWay}"
                                            BorderThickness="0"
                                            Focusable="False"
                                            ItemContainerStyle="{StaticResource ResourceKey=TextBoxSuggestionItemStyle}"
                                            ItemTemplate="{TemplateBinding ItemTemplate}"
                                            ItemTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                                            ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                            ScrollViewer.VerticalScrollBarVisibility="Auto" />
                                        <Border Visibility="{Binding Path=IsLoading, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource ResourceKey=BoolToVisConverter}}">
                                            <ContentPresenter ContentSource="LoadingContent" />
                                        </Border>
                                    </Grid>
                                </Border>
                            </Popup>

                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger SourceName="PART_Editor" Property="Text" Value="">
                            <Setter TargetName="PART_Watermark" Property="Visibility" Value="Visible" />
                        </Trigger>
                        <Trigger Property="IconPlacement" Value="Left">
                            <Setter TargetName="PART_Icon" Property="DockPanel.Dock" Value="Left" />
                        </Trigger>
                        <Trigger Property="IconPlacement" Value="Right">
                            <Setter TargetName="PART_Icon" Property="DockPanel.Dock" Value="Right" />
                        </Trigger>
                        <Trigger Property="Validation.HasError" Value="True">
                            <Setter Property="BorderBrush" Value="Red" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="editors:AutoCompleteComboBox">
        <Setter Property="Focusable" Value="True" />
        <Setter Property="SuggestionBackground" Value="White" />
        <Setter Property="BorderThickness" Value="0,0,0,1" />
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="VerticalContentAlignment" Value="Top" />
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="AllowDrop" Value="true" />
        <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst" />
        <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type editors:AutoCompleteComboBox}">
                    <Grid>
                        <DockPanel>
                            <ContentPresenter
                                x:Name="PART_Icon"
                                ContentSource="Icon"
                                Visibility="{TemplateBinding IconVisibility}" />
                            <Grid>
                                <TextBlock
                                    x:Name="PART_Watermark"
                                    HorizontalAlignment="Left"
                                    VerticalAlignment="Center"
                                    DockPanel.Dock="Left"
                                    Focusable="False"
                                    Foreground="Gray"
                                    Text="{TemplateBinding Watermark}"
                                    Visibility="Collapsed" />
                                <DockPanel Margin="3,0">
                                    <Expander x:Name="PART_Expander" DockPanel.Dock="Right" />
                                    <TextBox
                                        x:Name="PART_Editor"
                                        HorizontalAlignment="Stretch"
                                        VerticalAlignment="Center"
                                        CharacterCasing="{Binding Path=CharacterCasing, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay}"
                                        Focusable="True"
                                        MaxLength="{Binding Path=MaxLength, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay}" />
                                </DockPanel>
                            </Grid>
                        </DockPanel>
                        <Popup
                            x:Name="PART_Popup"
                            MinWidth="{TemplateBinding ActualWidth}"
                            MinHeight="25"
                            MaxHeight="600"
                            AllowsTransparency="True"
                            Focusable="False"
                            HorizontalOffset="0"
                            IsOpen="{Binding Path=IsDropDownOpen, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay}"
                            PopupAnimation="Slide">
                            <Border
                                Padding="2"
                                Background="{Binding Path=SuggestionBackground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=editors:AutoCompleteComboBox}, Mode=OneWay}"
                                BorderBrush="Gray"
                                BorderThickness="1"
                                CornerRadius="5">
                                <Grid>
                                    <ListBox
                                        x:Name="PART_Selector"
                                        MaxWidth="{Binding Path=MaxPopupWidth, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay}"
                                        MaxHeight="{Binding Path=MaxPopupHeight, RelativeSource={RelativeSource Mode=TemplatedParent}, Mode=TwoWay}"
                                        Background="{Binding Path=SuggestionBackground, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=editors:AutoCompleteComboBox}, Mode=OneWay}"
                                        BorderThickness="0"
                                        Focusable="False"
                                        ItemContainerStyle="{StaticResource ResourceKey=ComboBoxSuggestionItemStyle}"
                                        ItemTemplate="{TemplateBinding ItemTemplate}"
                                        ItemTemplateSelector="{TemplateBinding ItemTemplateSelector}"
                                        ScrollViewer.HorizontalScrollBarVisibility="Auto"
                                        ScrollViewer.VerticalScrollBarVisibility="Auto" />
                                    <Border Visibility="{Binding Path=IsLoading, RelativeSource={RelativeSource Mode=TemplatedParent}, Converter={StaticResource ResourceKey=BoolToVisConverter}}">
                                        <ContentPresenter ContentSource="LoadingContent" />
                                    </Border>
                                </Grid>
                            </Border>
                        </Popup>

                    </Grid>
                    <!--</Border>-->
                    <ControlTemplate.Triggers>
                        <Trigger SourceName="PART_Editor" Property="Text" Value="">
                            <Setter TargetName="PART_Watermark" Property="Visibility" Value="Visible" />
                        </Trigger>
                        <Trigger Property="IconPlacement" Value="Left">
                            <Setter TargetName="PART_Icon" Property="DockPanel.Dock" Value="Left" />
                        </Trigger>
                        <Trigger Property="IconPlacement" Value="Right">
                            <Setter TargetName="PART_Icon" Property="DockPanel.Dock" Value="Right" />
                        </Trigger>
                        <Trigger Property="Validation.HasError" Value="True">
                            <Setter Property="BorderBrush" Value="Red" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>
