<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. -->
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ModernWpf.Controls"
    xmlns:primitives="clr-namespace:ModernWpf.Controls.Primitives"
    xmlns:sys="clr-namespace:System;assembly=mscorlib">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/ModernWpf;component/Styles/Button.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <Thickness x:Key="AutoSuggestBoxTopHeaderMargin">0,0,0,8</Thickness>
    <Thickness x:Key="AutoSuggestBoxInnerButtonMargin">1,3</Thickness>
    <Thickness x:Key="AutoSuggestBoxDeleteButtonMargin">0,4</Thickness>
    <Thickness x:Key="AutoSuggestBoxQueryButtonPadding">3,2</Thickness>
    <sys:Double x:Key="AutoSuggestBoxLeftButtonMargin">3</sys:Double>
    <sys:Double x:Key="AutoSuggestBoxRightButtonMargin">4</sys:Double>

    <Style TargetType="TextBox" x:Key="AutoSuggestBoxTextBoxStyle">
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="MinWidth" Value="{DynamicResource TextControlThemeMinWidth}" />
        <Setter Property="MinHeight" Value="{DynamicResource TextControlThemeMinHeight}" />
        <Setter Property="Foreground" Value="{DynamicResource TextControlForeground}" />
        <Setter Property="Background" Value="{DynamicResource TextControlBackground}" />
        <Setter Property="BorderBrush" Value="{DynamicResource TextControlBorderBrush}" />
        <Setter Property="SelectionBrush" Value="{DynamicResource TextControlSelectionHighlightColor}" />
        <Setter Property="BorderThickness" Value="{DynamicResource TextControlBorderThemeThickness}" />
        <Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" />
        <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" />
        <Setter Property="ScrollViewer.IsDeferredScrollingEnabled" Value="False" />
        <Setter Property="Padding" Value="{DynamicResource TextControlThemePadding}" />
        <Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="AllowDrop" Value="true" />
        <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
        <Setter Property="ContextMenu" Value="{DynamicResource TextControlContextMenu}" />
        <Setter Property="local:TextContextMenu.UsingTextContextMenu" Value="True" />
        <Setter Property="primitives:TextBoxHelper.IsEnabled" Value="True" />
        <Setter Property="Validation.ErrorTemplate" Value="{DynamicResource TextControlValidationErrorTemplate}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="TextBox">
                    <ControlTemplate.Resources>
                        <Style TargetType="ContentControl">
                            <Setter Property="HorizontalContentAlignment" Value="Left" />
                            <Setter Property="VerticalContentAlignment" Value="Top" />
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="ContentControl">
                                        <ContentPresenter
                                            Margin="{TemplateBinding Padding}"
                                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                        <Style x:Key="DeleteButtonStyle" TargetType="Button" BasedOn="{StaticResource DefaultButtonStyle}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="Button">
                                        <ControlTemplate.Resources>
                                            <StreamGeometry x:Key="Cancel">M 10.888672 10 L 17.626953 16.748047 L 16.748047 17.626953 L 10 10.888672 L 3.251953 17.626953 L 2.373047 16.748047 L 9.111328 10 L 2.373047 3.251953 L 3.251953 2.373047 L 10 9.111328 L 16.748047 2.373047 L 17.626953 3.251953 Z</StreamGeometry>
                                        </ControlTemplate.Resources>
                                        <Border
                                            x:Name="ButtonLayoutGrid"
                                            BorderBrush="{DynamicResource TextControlButtonBorderBrush}"
                                            BorderThickness="{TemplateBinding BorderThickness}"
                                            Background="{DynamicResource TextControlButtonBackground}"
                                            Margin="{StaticResource AutoSuggestBoxDeleteButtonMargin}"
                                            CornerRadius="{DynamicResource ControlCornerRadius}">
                                            <local:FontIconFallback
                                                x:Name="GlyphElement"
                                                Foreground="{DynamicResource TextControlButtonForeground}"
                                                VerticalAlignment="Center"
                                                HorizontalAlignment="Center"
                                                FontStyle="Normal"
                                                FontSize="{DynamicResource AutoSuggestBoxIconFontSize}"
                                                Data="{StaticResource Cancel}"
                                                FontFamily="{DynamicResource SymbolThemeFontFamily}" />
                                        </Border>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsMouseOver" Value="true">
                                                <Setter Property="Background" TargetName="ButtonLayoutGrid" Value="{DynamicResource TextControlButtonBackgroundPointerOver}" />
                                                <Setter Property="BorderBrush" TargetName="ButtonLayoutGrid" Value="{DynamicResource TextControlButtonBorderBrushPointerOver}" />
                                                <Setter Property="Foreground" TargetName="GlyphElement" Value="{DynamicResource TextControlButtonForegroundPointerOver}" />
                                            </Trigger>
                                            <Trigger Property="IsPressed" Value="true">
                                                <Setter Property="Background" TargetName="ButtonLayoutGrid" Value="{DynamicResource TextControlButtonBackgroundPressed}" />
                                                <Setter Property="BorderBrush" TargetName="ButtonLayoutGrid" Value="{DynamicResource TextControlButtonBorderBrushPressed}" />
                                                <Setter Property="Foreground" TargetName="GlyphElement" Value="{DynamicResource TextControlButtonForegroundPressed}" />
                                            </Trigger>
                                            <Trigger Property="IsEnabled" Value="false">
                                                <Setter Property="Opacity" TargetName="ButtonLayoutGrid" Value="0" />
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                        <Style x:Key="QueryButtonStyle" TargetType="Button" BasedOn="{StaticResource DefaultButtonStyle}">
                            <Setter Property="Template">
                                <Setter.Value>
                                    <ControlTemplate TargetType="Button">
                                        <Border
                                            x:Name="Border"
                                            Background="{DynamicResource TextControlButtonBackground}"
                                            BorderBrush="{DynamicResource TextControlButtonBorderBrush}"
                                            BorderThickness="{TemplateBinding BorderThickness}"
                                            CornerRadius="{TemplateBinding primitives:ControlHelper.CornerRadius}"
                                            Margin="{DynamicResource AutoSuggestBoxInnerButtonMargin}"
                                            Padding="{TemplateBinding Padding}">
                                            <ContentPresenter
                                                x:Name="ContentPresenter"
                                                Content="{TemplateBinding Content}"
                                                ContentTemplate="{TemplateBinding ContentTemplate}"
                                                TextElement.FontSize="{DynamicResource AutoSuggestBoxIconFontSize}"
                                                HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
                                        </Border>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsMouseOver" Value="True">
                                                <Setter TargetName="Border" Property="Background" Value="{DynamicResource TextControlButtonBackgroundPointerOver}" />
                                                <Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource TextControlButtonBorderBrushPointerOver}" />
                                                <Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource TextControlButtonForegroundPointerOver}" />
                                            </Trigger>
                                            <Trigger Property="IsPressed" Value="True">
                                                <Setter TargetName="Border" Property="Background" Value="{DynamicResource TextControlButtonBackgroundPressed}" />
                                                <Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource TextControlButtonBorderBrushPressed}" />
                                                <Setter TargetName="ContentPresenter" Property="TextElement.Foreground" Value="{DynamicResource TextControlButtonForegroundPressed}" />
                                            </Trigger>
                                            <Trigger Property="IsEnabled" Value="False">
                                                <Setter TargetName="Border" Property="Opacity" Value="0" />
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Setter.Value>
                            </Setter>
                        </Style>
                    </ControlTemplate.Resources>
                    <Grid SnapsToDevicePixels="True">
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="ButtonStates">
                                <VisualState x:Name="ButtonVisible">

                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="DeleteButton" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="ButtonCollapsed" />

                            </VisualStateGroup>

                        </VisualStateManager.VisualStateGroups>

                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition Width="Auto" />
                            <ColumnDefinition  primitives:ColumnDefinitionHelper.PixelWidth="{DynamicResource AutoSuggestBoxRightButtonMargin}" />
                        </Grid.ColumnDefinitions>

                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Border
                            x:Name="BorderElement"
                            Grid.Row="1"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Grid.ColumnSpan="4"
                            Grid.RowSpan="1"
                            CornerRadius="{TemplateBinding primitives:ControlHelper.CornerRadius}" />
                        <local:ContentPresenterEx
                            x:Name="HeaderContentPresenter"
                            Visibility="{TemplateBinding primitives:ControlHelper.HeaderVisibility}"
                            Grid.Row="0"
                            Foreground="{DynamicResource TextControlHeaderForeground}"
                            Margin="{DynamicResource AutoSuggestBoxTopHeaderMargin}"
                            Grid.ColumnSpan="4"
                            Content="{TemplateBinding primitives:ControlHelper.Header}"
                            ContentTemplate="{TemplateBinding primitives:ControlHelper.HeaderTemplate}"
                            FontWeight="Normal"
                            TextWrapping="Wrap"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        <ScrollViewer
                            x:Name="PART_ContentHost"
                            Grid.Row="1"
                            Style="{DynamicResource TextControlContentHostStyle}"
                            HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                            VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                            IsDeferredScrollingEnabled="{TemplateBinding ScrollViewer.IsDeferredScrollingEnabled}"
                            VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                            HorizontalContentAlignment="{TemplateBinding HorizontalContentAlignment}"
                            Margin="{TemplateBinding BorderThickness}"
                            Padding="{TemplateBinding Padding}"
                            Focusable="False"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        <ContentControl
                            x:Name="PlaceholderTextContentPresenter"
                            Grid.Row="1"
                            Foreground="{DynamicResource TextControlPlaceholderForeground}"
                            Margin="{TemplateBinding BorderThickness}"
                            VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                            HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                            Padding="{TemplateBinding Padding}"
                            Focusable="False"
                            Grid.ColumnSpan="4"
                            Content="{TemplateBinding primitives:ControlHelper.PlaceholderText}"
                            IsHitTestVisible="False" />
                        <Button
                            x:Name="DeleteButton"
                            Grid.Row="1"
                            primitives:ControlHelper.CornerRadius="{TemplateBinding primitives:ControlHelper.CornerRadius}"
                            Style="{StaticResource DeleteButtonStyle}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Padding="{DynamicResource HelperButtonThemePadding}"
                            Focusable="False"
                            Grid.Column="1"
                            Visibility="Collapsed"
                            FontSize="{TemplateBinding FontSize}"
                            Width="32"
                            VerticalAlignment="Stretch"
                            primitives:TextBoxHelper.IsDeleteButton="True" />
                        <Button
                            x:Name="QueryButton"
                            Grid.Row="1"
                            Grid.Column="2"
                            primitives:ControlHelper.CornerRadius="{TemplateBinding primitives:ControlHelper.CornerRadius}"
                            Style="{StaticResource QueryButtonStyle}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            Margin="2,0,0,0"
                            Padding="{DynamicResource HelperButtonThemePadding}"
                            Focusable="False"
                            FontSize="{TemplateBinding FontSize}"
                            Width="32"
                            Height="28"
                            VerticalAlignment="Stretch" />
                        <ContentPresenter
                            x:Name="DescriptionPresenter"
                            Grid.Row="2"
                            Grid.ColumnSpan="4"
                            Content="{TemplateBinding primitives:ControlHelper.Description}"
                            Visibility="{TemplateBinding primitives:ControlHelper.DescriptionVisibility}"
                            TextElement.Foreground="{DynamicResource SystemControlDescriptionTextForegroundBrush}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />

                    </Grid>

                    <ControlTemplate.Triggers>
                        <!-- Disabled -->
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="HeaderContentPresenter" Property="Foreground" Value="{DynamicResource TextControlHeaderForegroundDisabled}" />
                            <Setter Property="Background" Value="{DynamicResource TextControlBackgroundDisabled}" />
                            <Setter TargetName="BorderElement" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushDisabled}" />
                            <Setter Property="Foreground" Value="{DynamicResource TextControlForegroundDisabled}" />
                            <Setter TargetName="PlaceholderTextContentPresenter" Property="Foreground" Value="{DynamicResource TextControlPlaceholderForegroundDisabled}" />
                        </Trigger>
                        <!-- PointerOver -->
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="BorderElement" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushPointerOver}" />
                            <Setter Property="Background" Value="{DynamicResource TextControlBackgroundPointerOver}" />
                            <Setter TargetName="PlaceholderTextContentPresenter" Property="Foreground" Value="{DynamicResource TextControlPlaceholderForegroundPointerOver}" />
                            <Setter Property="Foreground" Value="{DynamicResource TextControlForegroundPointerOver}" />
                        </Trigger>
                        <!-- Focused -->
                        <Trigger Property="IsSelectionActive" Value="True">
                            <Setter TargetName="PlaceholderTextContentPresenter" Property="Foreground" Value="{DynamicResource TextControlPlaceholderForegroundFocused}" />
                            <Setter Property="Background" Value="{DynamicResource TextControlBackgroundFocused}" />
                            <Setter TargetName="BorderElement" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushFocused}" />
                            <Setter TargetName="BorderElement" Property="BorderThickness" Value="{DynamicResource TextControlBorderThemeThicknessFocused}" />
                            <Setter Property="Foreground" Value="{DynamicResource TextControlForegroundFocused}" />
                            <Setter TargetName="QueryButton" Property="Foreground" Value="{DynamicResource TextControlButtonForeground}" />
                        </Trigger>
                        <Trigger Property="primitives:TextBoxHelper.HasText" Value="True">
                            <Setter TargetName="PlaceholderTextContentPresenter" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsKeyboardFocused" Value="True" />
                    <Condition Property="primitives:TextBoxHelper.HasText" Value="True" />
                    <Condition Property="IsReadOnly" Value="False" />
                    <Condition Property="AcceptsReturn" Value="False" />
                    <Condition Property="TextWrapping" Value="NoWrap" />
                </MultiTrigger.Conditions>
                <Setter Property="primitives:TextBoxHelper.IsDeleteButtonVisible" Value="True" />
            </MultiTrigger>
        </Style.Triggers>
    </Style>

</ResourceDictionary>