<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:o="http://schemas.microsoft.com/winfx/2006/xaml/presentation/options"
                    xmlns:ge="clr-namespace:SourceChord.GridExtra;assembly=GridExtra.Wpf"
                    xmlns:dr="clr-namespace:Dragablz;assembly=Dragablz"
                    xmlns:controls="clr-namespace:MyPad.Views.Controls">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/Dragablz;component/Themes/Generic.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="Common.DragablzItem" TargetType="{x:Type dr:DragablzItem}" BasedOn="{StaticResource {x:Type dr:DragablzItem}}">
        <Setter Property="Foreground" Value="{DynamicResource MahApps.Brushes.Text}"/>
        <Setter Property="Background" Value="{x:Null}"/>
        <Setter Property="BorderBrush" Value="{x:Null}"/>
        <Setter Property="BorderThickness" Value="0"/>
        <Setter Property="IsTabStop" Value="False"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type dr:DragablzItem}">
                    <Border Background="{TemplateBinding Background}" 
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                            HorizontalAlignment="Stretch"
                            Focusable="False">
                        <Grid ge:GridEx.ColumnDefinition="*, Auto, 5">
                            <ContentPresenter x:Name="PART_ContentPresenter"
                                              Content="{TemplateBinding Content}"
                                              ContentTemplate="{TemplateBinding ContentTemplate}"
                                              ContentStringFormat="{TemplateBinding ContentStringFormat}"
                                              HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                              SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
                                              Margin="5 3"/>
                            <Thumb x:Name="PART_Thumb"
                                   Grid.Column="0"
                                   Style="{StaticResource InvisibleThumbStyle}"
                                   HorizontalAlignment="Stretch" 
                                   VerticalContentAlignment="Stretch"/>
                            <Button x:Name="PART_CloseButton"
                                    Grid.Column="1"
                                    Height="{DynamicResource MahApps.Font.Size.Button.ClearText}"
                                    Width="{DynamicResource MahApps.Font.Size.Button.ClearText}"
                                    Margin="0"
                                    Focusable="False"
                                    Background="Transparent"
                                    Command="{x:Static dr:TabablzControl.CloseItemCommand}"
                                    CommandParameter="{Binding RelativeSource={RelativeSource TemplatedParent}}">
                                <Button.Template>
                                    <ControlTemplate TargetType="{x:Type Button}">
                                        <Border Background="{TemplateBinding Background}">
                                            <Path x:Name="ButtonPath"
                                                  Margin="3"
                                                  HorizontalAlignment="Center"
                                                  VerticalAlignment="Center"
                                                  Stretch="Uniform"
                                                  Data="M0,0 L1,1 M0,1 L1,0"
                                                  Stroke="{DynamicResource MahApps.Brushes.Gray5}"
                                                  StrokeThickness="1"
                                                  StrokeEndLineCap="Flat"
                                                  StrokeStartLineCap="Flat"/>
                                        </Border>
                                        <ControlTemplate.Triggers>
                                            <Trigger Property="IsEnabled" Value="False">
                                                <Setter Property="Visibility" Value="Hidden"/>
                                            </Trigger>
                                            <Trigger Property="IsMouseOver" Value="True">
                                                <Setter Property="Background" Value="{DynamicResource MahApps.Brushes.Accent3}"/>
                                                <Setter TargetName="ButtonPath" Property="Stroke" Value="{DynamicResource MahApps.Brushes.Gray.MouseOver}"/>
                                            </Trigger>
                                            <Trigger Property="IsPressed" Value="true">
                                                <Setter Property="Background" Value="{DynamicResource MahApps.Brushes.Gray.MouseOver}"/>
                                                <Setter TargetName="ButtonPath" Property="Stroke" Value="{DynamicResource MahApps.Brushes.Gray5}"/>
                                            </Trigger>
                                        </ControlTemplate.Triggers>
                                    </ControlTemplate>
                                </Button.Template>
                                <Button.Visibility>
                                    <MultiBinding Converter="{StaticResource ShowDefaultCloseButtonConverter}">
                                        <Binding Path="ShowDefaultCloseButton" RelativeSource="{RelativeSource AncestorType={x:Type dr:TabablzControl}}"/>
                                        <Binding Path="FixedHeaderCount" RelativeSource="{RelativeSource AncestorType={x:Type dr:TabablzControl}}"/>
                                        <Binding Path="LogicalIndex" RelativeSource="{RelativeSource TemplatedParent}"/>
                                    </MultiBinding>
                                </Button.Visibility>
                            </Button>
                        </Grid>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="dr:TabablzControl.IsWrappingTabItem" Value="True">
                            <Setter TargetName="PART_ContentPresenter" Property="Content" Value="{Binding DataContext.Header, RelativeSource={RelativeSource TemplatedParent}, Mode=OneWay}"/>
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Foreground" Value="White"/>
                            <Setter Property="Background" Value="{DynamicResource MahApps.Brushes.AccentBase}"/>
                        </Trigger>
                        <Trigger Property="IsSelected" Value="True">
                            <Setter Property="Foreground" Value="White"/>
                            <Setter Property="Background" Value="{DynamicResource MahApps.Brushes.Accent}"/>
                        </Trigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="IsMouseOver" Value="False"/>
                                <Condition Property="IsSelected"  Value="False"/>
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_CloseButton" Property="Opacity" Value="0.2"/>
                        </MultiTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style x:Key="Common.TabablzControl" TargetType="{x:Type dr:TabablzControl}" BasedOn="{StaticResource {x:Type dr:TabablzControl}}">
        <Setter Property="ItemContainerStyle" Value="{StaticResource Common.DragablzItem}"/>
        <Setter Property="Foreground" Value="{DynamicResource MahApps.Brushes.Text}"/>
        <Setter Property="Background" Value="{DynamicResource MahApps.Brushes.Control.Background}"/>
        <Setter Property="BorderBrush" Value="{DynamicResource MahApps.Brushes.Control.Background}"/>
        <Setter Property="BorderThickness" Value="0"/>
    </Style>
    
    <Style TargetType="{x:Type dr:DragablzItem}"              BasedOn="{StaticResource Common.DragablzItem}"/>
    <Style TargetType="{x:Type dr:TabablzControl}"            BasedOn="{StaticResource Common.TabablzControl}"/>
    <Style TargetType="{x:Type controls:DraggableTabControl}" BasedOn="{StaticResource Common.TabablzControl}"/>

</ResourceDictionary>
