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

<!--=================================================================
            RibbonTab
    ==================================================================-->

<Style x:Key="{x:Type ribbon:RibbonTab}" TargetType="{x:Type ribbon:RibbonTab}">
    <Setter Property="controls:KeyTipService.IsKeyTipScope" Value="True"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="{x:Type ribbon:RibbonTab}">
                <Grid x:Name="MainGrid" Visibility="{TemplateBinding IsSelected, Converter={StaticResource BooleanToVisibilityConverterKey}}" ClipToBounds="True">
                    <Line x:Name="OuterLeftLine"
                          StrokeThickness="2" 
                          Stroke="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ContextualTabGroup.Background}"
                          X1="0"
                          Y1="0"
                          X2="{Binding RelativeSource={RelativeSource TemplatedParent},Path=TabHeaderLeft}"
                          Y2="0" />
                    <Line x:Name="OuterRightLine"
                          StrokeThickness="2" 
                          Stroke="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ContextualTabGroup.Background}"
                          X1="{Binding RelativeSource={RelativeSource TemplatedParent},Path=TabHeaderRight}"
                          Y1="0"
                          X2="{Binding RelativeSource={RelativeSource TemplatedParent},Path=ActualWidth}"
                          Y2="0" />
                    <ScrollViewer x:Name="ScrollViewer" Style="{StaticResource RibbonTabScrollViewer}">
#ifdef Net40
                        <Grid RenderOptions.ClearTypeHint="Enabled" >
                            <Canvas x:Name="BackgroundCanvas"
                                    Height="0"
                                    Width="0"
                                    HorizontalAlignment="Left"
                                    VerticalAlignment="Top"
                                    Margin="0,1,0,0">
                                <Rectangle x:Name="OpaqueRect"
                                           Height="{Binding ElementName=ScrollViewer,Path=ActualHeight}"
                                           Width="{Binding ElementName=ScrollViewer,Path=ActualWidth}"
                                           Fill="{Binding RelativeSource={RelativeSource Self},Path=(ribbon:RibbonControlService.Ribbon).Background}"/>
                                <Rectangle x:Name="OverlayRect"
                                           Height="{Binding ElementName=ScrollViewer,Path=ActualHeight}"
                                           Width="{Binding ElementName=ScrollViewer,Path=ActualWidth}"
                                           Fill="{StaticResource RibbonOverlayBackgroundBrushKey}"/>
                                <Rectangle x:Name="InnerOverlayRect"
                                           Height="{Binding ElementName=ScrollViewer,Path=ActualHeight}"
                                           Width="{Binding ElementName=ScrollViewer,Path=ActualWidth}"
                                           Fill="{StaticResource RibbonInnerBorderBrushKey}"/>
                            </Canvas>
#endif
                            <ItemsPresenter x:Name="ItemsPresenter" />
#ifdef Net40
                        </Grid>
#endif
                    </ScrollViewer>
                </Grid>
                <ControlTemplate.Triggers>
#ifdef Net40
                    <Trigger SourceName="ScrollViewer"
                             Property="ScrollViewer.CanContentScroll"
                             Value="false">
                        <Setter TargetName="OpaqueRect" 
                                Property="Canvas.Top" 
                                Value="{Binding ElementName=ScrollViewer, Path=VerticalOffset}" />
                        <Setter TargetName="OpaqueRect" 
                                Property="Canvas.Left" 
                                Value="{Binding ElementName=ScrollViewer, Path=HorizontalOffset}" />
                        <Setter TargetName="OverlayRect" 
                                Property="Canvas.Top" 
                                Value="{Binding ElementName=ScrollViewer, Path=VerticalOffset}" />
                        <Setter TargetName="OverlayRect" 
                                Property="Canvas.Left" 
                                Value="{Binding ElementName=ScrollViewer, Path=HorizontalOffset}" />
                        <Setter TargetName="InnerOverlayRect" 
                                Property="Canvas.Top" 
                                Value="{Binding ElementName=ScrollViewer, Path=VerticalOffset}" />
                        <Setter TargetName="InnerOverlayRect" 
                                Property="Canvas.Left" 
                                Value="{Binding ElementName=ScrollViewer, Path=HorizontalOffset}" />
                    </Trigger>
#endif
                    <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=ContextualTabGroup}" Value="{x:Null}"/>
                        </MultiDataTrigger.Conditions>
                        <Setter TargetName="OuterLeftLine" Property="Stroke" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type ribbon:RibbonTab}}, Path=Ribbon.BorderBrush}" />
                        <Setter TargetName="OuterRightLine" Property="Stroke" Value="{Binding RelativeSource={RelativeSource AncestorType={x:Type ribbon:RibbonTab}}, Path=Ribbon.BorderBrush}" />
                    </MultiDataTrigger>
#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
#ifdef Net40
                        <Setter TargetName="BackgroundCanvas" Property="Visibility" Value="Collapsed" />
#endif
                        <Setter TargetName="OuterLeftLine" Property="Stroke" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"/>
                        <Setter TargetName="OuterRightLine" Property="Stroke" Value="{DynamicResource {x:Static SystemColors.ControlDarkBrushKey}}"/>
                    </DataTrigger>
                </ControlTemplate.Triggers>
            </ControlTemplate>
        </Setter.Value>
    </Setter>
</Style>
