<UserControl x:Class="CatelSample.Views.Base.Controls.ClosableTabItem"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:CatelSample.Views.Base.Controls"
             xmlns:catel="http://catel.codeplex.com"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    
    <StackPanel Orientation="Horizontal">
        <TextBlock Text="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:ClosableTabItem}}, Path=Title}"/>
        <Button Click="OnCloseButtonClick" Margin="5,0,0,0" HorizontalAlignment="Right" VerticalAlignment="Center" x:Name="PART_CLOSE" Height="14" Width="14" Cursor="Hand" Foreground="#FF919191" ToolTip="{catel:LanguageBinding Close}" Style="{DynamicResource WindowButtonStyle}" IsCancel="True" Visibility="{Binding RelativeSource={RelativeSource AncestorType={x:Type local:ClosableTabItem}}, Path=CanClose, Converter={catel:BooleanToCollapsingVisibilityConverter}}">
            <Button.Template>
                <ControlTemplate>
                    <Grid Background="{TemplateBinding Background}">
                        <Path x:Name="ButtonPath" 
                            Margin="2"
                            Data="M0,0 L1,1 M0,1 L1,0"
                            Stroke="{StaticResource CloseButtonStroke}" 
                            StrokeThickness="2"
                            StrokeStartLineCap="Flat"
                            StrokeEndLineCap="Flat"
                            Stretch="Uniform"
                            VerticalAlignment="Center"
                            HorizontalAlignment="Center"/>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsSelected, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=TabItem}}" Value="false"/>
                                <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=TabItem}}" Value="false"/>
                            </MultiDataTrigger.Conditions>
                            <MultiDataTrigger.Setters>
                                <Setter Property="Visibility" Value="Hidden"/>
                            </MultiDataTrigger.Setters>
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding Name, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type TabItem}}}" Value="Start"/>
                            </MultiDataTrigger.Conditions>
                            <MultiDataTrigger.Setters>
                                <Setter Property="Visibility" Value="Collapsed" />
                            </MultiDataTrigger.Setters>
                        </MultiDataTrigger>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Visibility" Value="Collapsed" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="ButtonPath" Property="Stroke" Value="{StaticResource CloseButtonStrokeHighlighted}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Button.Template>
        </Button>
    </StackPanel>
</UserControl>
