<!-- [[Generic]] -->

    <!-- RibbonTextBox -->
    <SolidColorBrush x:Key="RibbonTextBoxDisabledBorderBrushKey" Color="#90B1BBC6" />
    <SolidColorBrush x:Key="RibbonTextBoxDisabledBackgroundBrushKey" Color="#90DEDEDE" />


    <!--=================================================================
                RibbonTextBox
        ==================================================================-->

    <Style x:Key="{x:Type ribbon:RibbonTextBox}" TargetType="{x:Type ribbon:RibbonTextBox}">
        <Setter Property="Background" Value="{StaticResource RibbonTextBoxOverlayBrushKey}"/>
        <Setter Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource Self}, Path=Ribbon.BorderBrush}"/>
        <Setter Property="BorderThickness" Value="1"/>
        <Setter Property="AllowDrop" Value="True"/>
        <Setter Property="FocusVisualStyle" Value="{x:Null}"/>
        <Setter Property="TextBoxWidth" Value="80" />
        <Setter Property="MouseOverBorderBrush" Value="{Binding RelativeSource={RelativeSource Self}, Path=Ribbon.BorderBrush}" />
        <Setter Property="MouseOverBackground" Value="White" />
        <Setter Property="FocusedBorderBrush" Value="{Binding RelativeSource={RelativeSource Self}, Path=Ribbon.BorderBrush}" />
        <Setter Property="FocusedBackground" Value="White" />
        <Setter Property="ToolTipService.InitialShowDelay" Value="{StaticResource RibbonToolTipInitialShowDelayKey}" />
        <Setter Property="ToolTipService.ShowDuration" Value="{StaticResource RibbonToolTipShowDurationKey}" />
        <Setter Property="ToolTipService.BetweenShowDelay" Value="{StaticResource RibbonToolTipBetweenShowDelayKey}" />
        <Setter Property="QuickAccessToolBarControlSizeDefinition">
            <Setter.Value>
                <ribbon:RibbonControlSizeDefinition ImageSize="Collapsed" IsLabelVisible="True" />
            </Setter.Value>
        </Setter>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ribbon:RibbonTextBox}">
                    <Border x:Name="MainBorder" Margin="1">
                        <Grid Margin="1,0,1,0"
                              SnapsToDevicePixels="True">
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="Auto"/>
                                <ColumnDefinition x:Name="OuterTextColumn"  Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="Auto"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Image x:Name="Image"
                                   Source="{TemplateBinding LargeImageSource}"
                                   RenderOptions.BitmapScalingMode="NearestNeighbor"
                                   VerticalAlignment="Center"
                                   HorizontalAlignment="Center"
                                   Grid.Row="0"
                                   Grid.Column="1"
                                   Margin="1"
                                   Width="32"
                                   Height="32" />
                            <Grid x:Name="Grid"
                                  Grid.Row="1"
                                  Grid.Column="1"
                                  VerticalAlignment="Center"
                                  HorizontalAlignment="Center">
                                <Grid Name="InnerGrid"
                                      VerticalAlignment="Top"
                                      HorizontalAlignment="Center"
                                      Margin="1">
                                    <Grid.ColumnDefinitions>
                                        <ColumnDefinition Width="Auto"/>
                                        <ColumnDefinition x:Name="TextColumn" Width="Auto"/>
                                    </Grid.ColumnDefinitions>
                                    <Grid x:Name="TwoLineTextPanel"
                                          Grid.Column="0"
                                          VerticalAlignment="Center"
                                          HorizontalAlignment="Center">
                                        <ribbon:RibbonTwoLineText x:Name="TwoLineText"
                                                                  Text="{TemplateBinding Label}"
                                                                  TextAlignment="Center"
                                                                  LineHeight="13px"
                                                                  LineStackingStrategy="BlockLineHeight"
                                                                  Margin="2,0,2,0" />
                                        <Rectangle x:Name="FocusVisual"
                                                   Margin="1"
                                                   StrokeThickness="1"
                                                   Stroke="Black"
                                                   StrokeDashArray="1 2"
                                                   Visibility="Collapsed"/>
                                    </Grid>
                                    <Border x:Name="Border"
                                            Grid.Column="1"
                                            BorderThickness="{TemplateBinding BorderThickness}"
                                            BorderBrush="{TemplateBinding BorderBrush}"
                                            Background="{TemplateBinding Background}"
                                            Height="{StaticResource RibbonTextBoxHeight}"
                                            HorizontalAlignment="Center"
                                            VerticalAlignment="Center"
                                            Margin="2,0,2,0">
                                        <!--Note: ScrollViewer picks up HorizontalContentAlignment from the template and applies it to the hosted
                                        TextBox in 4.0, don't set it on the template, we want the default value - Left-->
                                    <ScrollViewer x:Name="PART_ContentHost"
                                                  Margin="0,1,0,1" 
                                                  Width="{TemplateBinding TextBoxWidth}"
                                                  VerticalAlignment="Center" />
                                    </Border>
                                </Grid>
                            </Grid>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>

                        <!-- Star Variant -->
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=ControlSizeDefinition.Width.IsStar}" Value="True">
                            <Setter TargetName="TextColumn" Property="Width" Value="*"/>
                            <Setter TargetName="OuterTextColumn" Property="Width" Value="*"/>
                            <Setter TargetName="PART_ContentHost" Property="Width" Value="Auto"/>
                            <Setter TargetName="Border" Property="HorizontalAlignment" Value="Stretch"/>
                            <Setter TargetName="Grid" Property="HorizontalAlignment" Value="Stretch"/>
                            <Setter TargetName="InnerGrid" Property="HorizontalAlignment" Value="Stretch"/>
                        </DataTrigger>
                        
                        
                        <!-- Large Variant -->
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=ControlSizeDefinition.ImageSize}" Value="Large">
                            <Setter Property="MinWidth" Value="44"/>
                            <Setter Property="Height" Value="66"/>
                            <Setter TargetName="Image" Property="Height" Value="32" />
                            <Setter TargetName="Image" Property="Width" Value="32" />
                            <Setter TargetName="Grid" Property="MinHeight" Value="26" />
                            <Setter TargetName="TwoLineText" Property="HasTwoLines" Value="True" />
                        </DataTrigger>

                        <!-- Medium or Small Variant -->
                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=ControlSizeDefinition.ImageSize}" Value="Small">
                            <Setter Property="Height" Value="{StaticResource RibbonSmallControlHeight}"/>
                            <Setter TargetName="Image" Property="Source" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=SmallImageSource}" />
                            <Setter TargetName="Image" Property="Height" Value="16" />
                            <Setter TargetName="Image" Property="Width" Value="16" />
                            <Setter TargetName="Image" Property="HorizontalAlignment" Value="Left" />
                            <Setter TargetName="Image" Property="Margin" Value="2,0,1,0" />
                            <Setter TargetName="TwoLineText" Property="Margin" Value="2,0,1,0" />
                            <Setter TargetName="TwoLineText" Property="HasTwoLines" Value="False" />
                            <Setter TargetName="Image" Property="Grid.Column" Value="0"/>
                            <Setter TargetName="Image" Property="Grid.Row" Value="1"/>
                            <Setter TargetName="InnerGrid" Property="Margin" Value="0"/>
                        </DataTrigger>

                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=ControlSizeDefinition.ImageSize}" Value="Collapsed" >
                            <Setter TargetName="Image" Property="Visibility" Value="Collapsed" />
                        </DataTrigger>

                        <DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=ControlSizeDefinition.IsLabelVisible}" Value="False" >
                            <Setter TargetName="TwoLineTextPanel" Property="Visibility" Value="Collapsed" />
                        </DataTrigger>
                        
                        <!-- IsMouseOver -->
                        <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
#ifdef Net45
                            <Condition Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="False"/>
#else
                            <Condition Binding="{Binding Path=HighContrast, Source={x:Static windows:SystemParameters2.Current}}" Value="False"/>
#endif
                            <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsMouseOver}" Value="True" />
                        </MultiDataTrigger.Conditions>
                            <Setter TargetName="Border" Property="Background" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=MouseOverBackground}" />
                            <Setter TargetName="Border" Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=MouseOverBorderBrush}" />
                        </MultiDataTrigger>

                        <!-- IsKeyboardFocused -->
                        <MultiDataTrigger>
                        <MultiDataTrigger.Conditions>
#ifdef Net45
                            <Condition Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="False"/>
#else
                            <Condition Binding="{Binding Path=HighContrast, Source={x:Static windows:SystemParameters2.Current}}" Value="False"/>
#endif
                            <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsKeyboardFocused}" Value="True" />
                        </MultiDataTrigger.Conditions>
                            <Setter TargetName="Border" Property="Background" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=MouseOverBackground}" />
                            <Setter TargetName="Border" Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=MouseOverBorderBrush}" />
                        </MultiDataTrigger>

                        <Trigger Property="ShowKeyboardCues" Value="True">
                            <Setter TargetName="FocusVisual" Property="Visibility" Value="Visible" />
                        </Trigger>

                        <!-- IsEnabled -->
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="Image" Property="Opacity" Value="0.5" />
                            <Setter TargetName="Border" Property="Background" Value="{StaticResource RibbonTextBoxDisabledBackgroundBrushKey}"/>
                            <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource RibbonTextBoxDisabledBorderBrushKey}"/>
                            <Setter TargetName="MainBorder" Property="TextElement.Foreground" Value="{StaticResource RibbonDisabledForegroundBrushKey}"/>
                        </Trigger>
                        
                        <!-- IsInControlGroup -->
                        <Trigger Property="IsInControlGroup" Value="True">
                            <Setter TargetName="MainBorder" Property="BorderBrush" Value="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Ribbon.BorderBrush}" />
                            <Setter TargetName="MainBorder" Property="BorderThickness" Value="0,0,1,0" />
                        </Trigger>

                        <!-- HighContrast -->
#ifdef Net45
                        <DataTrigger Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="True">
#else
                        <DataTrigger Binding="{Binding Path=HighContrast, Source={x:Static windows:SystemParameters2.Current}}" Value="True">
#endif
                            <!-- This is a hack for v3.0 to set the caret color to something visible in high contrast. Switch to using CaretBrush in v4 -->
                            <Setter Property="Background" Value="{DynamicResource {x:Static SystemColors.WindowBrushKey}}" />
                            <Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.ControlLightBrushKey}}"/>
                            <Setter TargetName="Border" Property="Background" Value="Transparent"/>
                            <Setter TargetName="FocusVisual" Property="Stroke" Value="{DynamicResource {x:Static SystemColors.WindowFrameBrushKey}}" />
                            <Setter TargetName="MainBorder" Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.MenuTextBrushKey}}" />
                        </DataTrigger>

                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsInControlGroup}" Value="True" />
#ifdef Net45
                                <Condition Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="True"/>
#else
                                <Condition Binding="{Binding Path=HighContrast, Source={x:Static windows:SystemParameters2.Current}}" Value="True"/>
#endif
                            </MultiDataTrigger.Conditions>
                            <Setter TargetName="MainBorder" Property="BorderBrush" Value="{DynamicResource {x:Static SystemColors.ControlLightLightBrushKey}}" />
                        </MultiDataTrigger>

                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=IsEnabled}" Value="False" />
#ifdef Net45
                                <Condition Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="True"/>
#else
                                <Condition Binding="{Binding Path=HighContrast, Source={x:Static windows:SystemParameters2.Current}}" Value="True"/>
#endif
                            </MultiDataTrigger.Conditions>
                            <Setter TargetName="MainBorder" Property="TextElement.Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                        </MultiDataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
#ifdef Net40
        <Style.Resources>
            <Style TargetType="{x:Type ScrollViewer}">
                <Setter Property="ContentTemplate">
                    <Setter.Value>
                        <DataTemplate>
                            <Grid RenderOptions.ClearTypeHint="Enabled">
                                <Canvas x:Name="BackgroundCanvas"
                                        Height="0"
                                        Width="0"
                                        HorizontalAlignment="Left"
                                        VerticalAlignment="Top">
                                    <Rectangle x:Name="OpaqueRect"
                                        Height="{Binding ElementName=PART_ContentHost,Path=ActualHeight}"
                                        Width="{Binding ElementName=PART_ContentHost,Path=ActualWidth}"
                                        Fill="{Binding RelativeSource={RelativeSource AncestorType={x:Type ribbon:Ribbon}},Path=Background}" />
                                    <Rectangle x:Name="OverlayRect"
                                        Height="{Binding ElementName=PART_ContentHost,Path=ActualHeight}"
                                        Width="{Binding ElementName=PART_ContentHost,Path=ActualWidth}"
                                        Fill="{Binding RelativeSource={RelativeSource AncestorType={x:Type ribbon:RibbonTextBox}},Path=Background}" />
                                </Canvas>
                                <ContentPresenter Content="{Binding}" />
                            </Grid>
                            <DataTemplate.Triggers>
                                <DataTrigger Binding="{Binding RelativeSource={RelativeSource AncestorType={x:Type ScrollViewer}},Path=(ScrollViewer.CanContentScroll)}"
                                         Value="false">
                                    <Setter TargetName="OpaqueRect" 
                                            Property="Canvas.Top" 
                                            Value="{Binding ElementName=PART_SubMenuScrollViewer, Path=VerticalOffset}" />
                                    <Setter TargetName="OpaqueRect" 
                                            Property="Canvas.Left" 
                                            Value="{Binding ElementName=PART_SubMenuScrollViewer, Path=HorizontalOffset}" />
                                    <Setter TargetName="OverlayRect" 
                                            Property="Canvas.Top" 
                                            Value="{Binding ElementName=PART_SubMenuScrollViewer, Path=VerticalOffset}" />
                                    <Setter TargetName="OverlayRect" 
                                            Property="Canvas.Left" 
                                            Value="{Binding ElementName=PART_SubMenuScrollViewer, Path=HorizontalOffset}" />
                                </DataTrigger>
#ifdef Net45
                                <DataTrigger Binding="{Binding Path=(SystemParameters.HighContrast)}" Value="True">
#else
                                <DataTrigger Binding="{Binding Path=HighContrast, Source={x:Static windows:SystemParameters2.Current}}" Value="True">
#endif
                                    <Setter TargetName="BackgroundCanvas" Property="Visibility" Value="Collapsed" />
                                </DataTrigger>
                            </DataTemplate.Triggers>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>
        </Style.Resources>
#endif        
    </Style>
