<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="clr-namespace:XamlTheme.Controls"
                    xmlns:utils="clr-namespace:XamlTheme.Utils"
                    xmlns:themes="clr-namespace:XamlTheme">

    <utils:ZoomBoxRulerShiftMultiConverter x:Key="zoomBoxRulerShiftMultiConverter"/> 

    <Style TargetType="{x:Type controls:ZoomBox}">
        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="HorizontalScrollBarVisibility" Value="Visible"/>
        <Setter Property="VerticalScrollBarVisibility" Value="Visible"/>
        <Setter Property="UseLayoutRounding" Value="true"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:ZoomBox}">
                    <Border Background="{TemplateBinding Background}" 
                            BorderThickness="{TemplateBinding BorderThickness}" 
                            BorderBrush="{TemplateBinding BorderBrush}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                            UseLayoutRounding="{TemplateBinding UseLayoutRounding}">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition x:Name="RulerColumn" Width="20"/>
                                <ColumnDefinition Width="*"/>
                                <ColumnDefinition Width="Auto"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition x:Name="RulerRow" Height="20"/>
                                <RowDefinition Height="*"/>
                                <RowDefinition Height="Auto"/>
                            </Grid.RowDefinitions>
                            <Border x:Name="PART_ContentBorder" Grid.Column="1" Grid.Row="1" Background="Transparent">
                                <!-- ScrollContentPresenter -->
                                <ScrollContentPresenter x:Name="PART_ScrollContentPresenter"
                                                        ContentTemplate="{TemplateBinding ContentTemplate}" 
                                                        CanContentScroll="{TemplateBinding CanContentScroll}"/>
                            </Border>

                            <Path Grid.Row="0" Grid.Column="0" Height="20"  Data="M0,0 H5 V-5" Stroke="Black" Stretch="Fill" StrokeThickness="1" RenderOptions.EdgeMode="Aliased"/> 
                            <Path Grid.Row="0" Grid.Column="0" Height="20" Data="M3,0 V-6 M0,-3 H6" Stroke="Black" Stretch="Fill" StrokeThickness="1" RenderOptions.EdgeMode="Aliased" StrokeDashArray="1,1"/>
                   
                            <!-- Horizontal Ruler -->
                            <controls:Ruler x:Name="PART_HorizontalRuler" 
                                            Grid.Row="0" Grid.Column="1"
                                            Unit="{TemplateBinding Unit}">
                                <controls:Ruler.Shift>
                                    <MultiBinding Converter="{StaticResource zoomBoxRulerShiftMultiConverter}">
                                        <Binding Path="HorizontalOriginShift" RelativeSource="{RelativeSource TemplatedParent}"/>
                                        <Binding Path="Scale" RelativeSource="{RelativeSource Self}"/>
                                        <Binding Path="Unit" RelativeSource="{RelativeSource Self}"/>
                                    </MultiBinding>
                                </controls:Ruler.Shift>
                            </controls:Ruler>

                            <!-- Vertical Ruler -->
                            <controls:Ruler x:Name="PART_VerticalRuler" 
                                            Orientation="Vertical"
                                            Grid.Row="1" Grid.Column="0"
                                            Unit="{TemplateBinding Unit}">
                                <controls:Ruler.Shift>
                                    <MultiBinding Converter="{StaticResource zoomBoxRulerShiftMultiConverter}">
                                        <Binding Path="VerticalOriginShift" RelativeSource="{RelativeSource TemplatedParent}"/>
                                        <Binding Path="Scale" RelativeSource="{RelativeSource Self}"/>
                                        <Binding Path="Unit" RelativeSource="{RelativeSource Self}"/>
                                    </MultiBinding>
                                </controls:Ruler.Shift>  
                            </controls:Ruler>

                            <!-- Horizontal ScrollBar -->
                            <Grid Grid.Column="0" Grid.Row="2" Grid.ColumnSpan="2" 
                                  Background="{TemplateBinding ScrollBarBackground}">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="Auto"/> 
                                    <ColumnDefinition Width="*"/>
                                </Grid.ColumnDefinitions>
                                <ContentPresenter x:Name="RibbonContent" 
                                                  ContentSource="Ribbon"
                                                  Margin="{TemplateBinding Padding}"
                                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" 
                                                  HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                                  VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 
                                
                                <ScrollBar Visibility="{TemplateBinding ComputedHorizontalScrollBarVisibility}" 
                                           Grid.Column="1"
                                           x:Name="PART_HorizontalScrollBar"  
                                           Orientation="Horizontal" 
                                           Background="Transparent"
                                           Value="{Binding Path=HorizontalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" 
                                           ViewportSize="{TemplateBinding ViewportWidth}" 
                                           Minimum="0" 
                                           Maximum="{TemplateBinding ScrollableWidth}" 
                                           Style="{DynamicResource {x:Static themes:ResourceKeys.NormalScrollBarStyleKey}}"/>
                            </Grid>

                            <!-- Vertical ScrollBar -->
                            <ScrollBar Visibility="{TemplateBinding ComputedVerticalScrollBarVisibility}" 
                                       Grid.Column="2" Grid.Row="0" Grid.RowSpan="2" 
                                       x:Name="PART_VerticalScrollBar"  
                                       Orientation="Vertical" 
                                       Background="{TemplateBinding ScrollBarBackground}"
                                       Value="{Binding Path=VerticalOffset, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}}" 
                                       ViewportSize="{TemplateBinding ViewportHeight}" 
                                       Minimum="0" 
                                       Maximum="{TemplateBinding ScrollableHeight}"
                                       Style="{DynamicResource {x:Static themes:ResourceKeys.NormalScrollBarStyleKey}}"/>

                            <Rectangle Grid.Row="2" Grid.Column="2" Fill="{TemplateBinding ScrollBarBackground}"/>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsShowRuler" Value="False">
                            <Setter TargetName="RulerColumn" Property="Width" Value="0"/>
                            <Setter TargetName="RulerRow" Property="Height" Value="0"/>
                            <Setter TargetName="PART_HorizontalRuler" Property="Visibility" Value="Collapsed"/>
                            <Setter TargetName="PART_VerticalRuler" Property="Visibility" Value="Collapsed"/>
                        </Trigger> 
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>