<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Fluent="clr-namespace:Fluent"
                    xmlns:converters="clr-namespace:Fluent.Converters">

    <ControlTemplate TargetType="{x:Type Fluent:TextBox}"
                     x:Key="Fluent.Ribbon.ControlTemplates.TextBox">
        <Grid Width="Auto"
              Height="22"
              Background="Transparent">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <StackPanel Orientation="Horizontal"
                        Grid.ColumnSpan="1"
                        x:Name="PART_HeaderAndIconPanel"
                        HorizontalAlignment="Left"
                        Margin="0,0,4,0">
                <ContentPresenter x:Name="iconImage"
                                  Width="16"
                                  Height="16"
                                  VerticalAlignment="Center"
                                  Margin="3,0,0,0"
                                  Content="{converters:ObjectToImageConverter {Binding Icon, RelativeSource={RelativeSource TemplatedParent}}, '16,16', {Binding RelativeSource={RelativeSource TemplatedParent}}}" />

                <Grid>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition SharedSizeGroup="{Binding Path=(Fluent:RibbonGroupBoxWrapPanel.SharedSizeGroupName), RelativeSource={RelativeSource TemplatedParent}}" />
                    </Grid.ColumnDefinitions>
                    <TextBlock Text="{TemplateBinding Header}"
                               TextWrapping="Wrap"
                               VerticalAlignment="Center"
                               Margin="5,0,0,0"
                               x:Name="headerTextBlock" />
                </Grid>
            </StackPanel>

            <Border Height="Auto"
                    BorderThickness="1,1,1,1"
                    BorderBrush="{DynamicResource Fluent.Ribbon.Brushes.TextBox.BorderBrush}"
                    x:Name="PART_ContentBorder"
                    Background="{DynamicResource Fluent.Ribbon.Brushes.TextBox.Background}"
                    Grid.Column="1"
                    Grid.ColumnSpan="1"
                    Width="{TemplateBinding InputWidth}"
                    HorizontalAlignment="Right">
                <ScrollViewer Margin="0"
                              VerticalContentAlignment="{TemplateBinding VerticalContentAlignment}"
                              x:Name="PART_ContentHost" />
            </Border>
        </Grid>

        <ControlTemplate.Triggers>
            <Trigger Property="Icon"
                        Value="{x:Null}">
                <Setter Property="Visibility"
                        TargetName="iconImage"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="InputWidth"
                        Value="NaN">
                <Setter Property="HorizontalAlignment"
                        TargetName="PART_ContentBorder"
                        Value="Stretch" />
            </Trigger>
            <Trigger Property="Size"
                        Value="Middle">
                <Setter Property="Visibility"
                        TargetName="headerTextBlock"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="Size"
                        Value="Small">
                <Setter Property="Visibility"
                        TargetName="PART_HeaderAndIconPanel"
                        Value="Collapsed" />
            </Trigger>
            <Trigger Property="IsEnabled"
                        Value="False">
                <Setter Property="Background"
                        TargetName="PART_ContentBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.TextBox.Disabled.Background}" />
                <Setter Property="BorderBrush"
                        TargetName="PART_ContentBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.TextBox.Disabled.BorderBrush}" />
                <Setter Property="BorderBrush"
                        TargetName="PART_ContentHost"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.TextBox.Disabled.Background}" />
                <Setter Property="Opacity"
                        TargetName="iconImage"
                        Value="0.5" />
                <Setter Property="Opacity"
                        TargetName="headerTextBlock"
                        Value="0.5" />
                <Setter Property="Effect"
                        TargetName="iconImage">
                    <Setter.Value>
                        <Fluent:GrayscaleEffect />
                    </Setter.Value>
                </Setter>
            </Trigger>
            <Trigger Property="IsMouseOver"
                        Value="True">
                <Setter Property="BorderBrush"
                        TargetName="PART_ContentBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.TextBox.MouseOver.BorderBrush}" />
                <Setter Property="Background"
                        TargetName="PART_ContentHost"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.TextBox.MouseOver.Background}" />
                <Setter Property="Background"
                        TargetName="PART_ContentBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.TextBox.MouseOver.Background}" />
            </Trigger>
            <Trigger Property="IsKeyboardFocusWithin"
                        Value="True">
                <Setter Property="BorderBrush"
                        TargetName="PART_ContentBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.TextBox.MouseOver.BorderBrush}" />
                <Setter Property="Background"
                        TargetName="PART_ContentHost"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.TextBox.MouseOver.Background}" />
                <Setter Property="Background"
                        TargetName="PART_ContentBorder"
                        Value="{DynamicResource Fluent.Ribbon.Brushes.TextBox.MouseOver.Background}" />
            </Trigger>
        </ControlTemplate.Triggers>
    </ControlTemplate>

    <Style TargetType="{x:Type Fluent:TextBox}"
           BasedOn="{StaticResource {x:Type TextBoxBase}}">
        <Setter Property="Template"
                Value="{DynamicResource Fluent.Ribbon.ControlTemplates.TextBox}" />
        <Setter Property="VerticalContentAlignment"
                Value="Center" />
        <Setter Property="FocusVisualStyle"
                Value="{DynamicResource ControlStyleEmptyFocus}" />
        <Setter Property="Foreground"
                Value="{DynamicResource Fluent.Ribbon.Brushes.LabelTextBrush}" />
        <Setter Property="CaretBrush"
                Value="{DynamicResource Fluent.Ribbon.Brushes.TextBox.CaretBrush}" />
        <Setter Property="SelectionBrush" 
                Value="{DynamicResource Fluent.Ribbon.Brushes.TextBox.SelectionBrush}" />
    </Style>
</ResourceDictionary>