<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:Behaviours="clr-namespace:MahApps.Metro.Behaviours"
                    xmlns:Controls="clr-namespace:MahApps.Metro.Controls">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.TabControl.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <Style BasedOn="{StaticResource MetroTabControl}" TargetType="{x:Type TabControl}">
        <Setter Property="Controls:TabControlHelper.Transition" Value="Left" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TabControl}">
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition x:Name="ColumnDefinition0" />
                            <ColumnDefinition x:Name="ColumnDefinition1" Width="0" />
                        </Grid.ColumnDefinitions>
                        <Grid.RowDefinitions>
                            <RowDefinition x:Name="RowDefinition0" Height="Auto" />
                            <RowDefinition x:Name="RowDefinition1" Height="*" />
                        </Grid.RowDefinitions>
                        <Grid x:Name="HeaderPanelGrid"
                              Grid.Row="0"
                              Grid.Column="0"
                              Panel.ZIndex="1">
                            <Controls:Underline x:Name="Underline"
                                                Background="Transparent"
                                                BorderBrush="{TemplateBinding Controls:TabControlHelper.UnderlineBrush}"
                                                LineThickness="1"
                                                Placement="Bottom"
                                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                                Visibility="Collapsed" />
                            <TabPanel x:Name="HeaderPanel"
                                      IsItemsHost="true"
                                      KeyboardNavigation.TabIndex="1" />
                        </Grid>
                        <Border x:Name="ContentPanel"
                                Grid.Row="1"
                                Grid.Column="0"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                ClipToBounds="{TemplateBinding ClipToBounds}"
                                KeyboardNavigation.DirectionalNavigation="Contained"
                                KeyboardNavigation.TabIndex="2"
                                KeyboardNavigation.TabNavigation="Local"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}">
                            <Controls:TransitioningContentControl Behaviours:ReloadBehavior.OnSelectedTabChanged="True"
                                                                  RestartTransitionOnContentChange="True"
                                                                  Transition="{TemplateBinding Controls:TabControlHelper.Transition}"
                                                                  UseLayoutRounding="True">
                                <ContentPresenter x:Name="PART_SelectedContentHost"
                                                  Margin="{TemplateBinding Padding}"
                                                  ContentSource="SelectedContent"
                                                  SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                                  UseLayoutRounding="False" />
                            </Controls:TransitioningContentControl>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="Controls:TabControlHelper.Underlined" Value="TabPanel">
                            <Setter TargetName="Underline" Property="Visibility" Value="Visible" />
                        </Trigger>
                        <Trigger Property="TabStripPlacement" Value="Bottom">
                            <Setter TargetName="ContentPanel" Property="Grid.Row" Value="0" />
                            <Setter TargetName="HeaderPanelGrid" Property="Grid.Row" Value="1" />
                            <Setter TargetName="HeaderPanelGrid" Property="Margin" Value="2 0 2 2" />
                            <Setter TargetName="RowDefinition0" Property="Height" Value="*" />
                            <Setter TargetName="RowDefinition1" Property="Height" Value="Auto" />
                            <Setter TargetName="Underline" Property="Placement" Value="Top" />
                        </Trigger>
                        <Trigger Property="TabStripPlacement" Value="Left">
                            <Setter TargetName="ColumnDefinition0" Property="Width" Value="Auto" />
                            <Setter TargetName="ColumnDefinition1" Property="Width" Value="*" />
                            <Setter TargetName="ContentPanel" Property="Grid.Column" Value="1" />
                            <Setter TargetName="ContentPanel" Property="Grid.Row" Value="0" />
                            <Setter TargetName="HeaderPanelGrid" Property="Grid.Column" Value="0" />
                            <Setter TargetName="HeaderPanelGrid" Property="Grid.Row" Value="0" />
                            <Setter TargetName="HeaderPanelGrid" Property="Margin" Value="2 2 0 2" />
                            <Setter TargetName="RowDefinition0" Property="Height" Value="*" />
                            <Setter TargetName="RowDefinition1" Property="Height" Value="0" />
                            <Setter TargetName="Underline" Property="Placement" Value="Right" />
                        </Trigger>
                        <Trigger Property="TabStripPlacement" Value="Right">
                            <Setter TargetName="ColumnDefinition0" Property="Width" Value="*" />
                            <Setter TargetName="ColumnDefinition1" Property="Width" Value="Auto" />
                            <Setter TargetName="ContentPanel" Property="Grid.Column" Value="0" />
                            <Setter TargetName="ContentPanel" Property="Grid.Row" Value="0" />
                            <Setter TargetName="HeaderPanelGrid" Property="Grid.Column" Value="1" />
                            <Setter TargetName="HeaderPanelGrid" Property="Grid.Row" Value="0" />
                            <Setter TargetName="HeaderPanelGrid" Property="Margin" Value="0 2 2 2" />
                            <Setter TargetName="RowDefinition0" Property="Height" Value="*" />
                            <Setter TargetName="RowDefinition1" Property="Height" Value="0" />
                            <Setter TargetName="Underline" Property="Placement" Value="Left" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

</ResourceDictionary>