<UserControl
    x:Class="MpvNet.Windows.WPF.Controls.SearchControl"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:controls="clr-namespace:MpvNet.Windows.WPF.Controls"
    mc:Ignorable="d" 
    d:DesignHeight="450"
    d:DesignWidth="800"
    >
    
    <Grid Background="{Binding Theme.Background}">
        
        <TextBlock
            Name="HintTextBlock"
            Padding="6,1"
            VerticalAlignment="Center"
            Foreground="{Binding Theme.Foreground2}"
            Background="{Binding Theme.Background}"
            />
        
        <TextBox
            Name="SearchTextBox"
            Height="25"
            BorderThickness="2"
            Padding="2,2,20,2"
            Background="Transparent"
            Foreground="{Binding Theme.Foreground}"
            CaretBrush="{Binding Theme.Foreground}"
            GotFocus="SearchTextBox_GotFocus"
            PreviewMouseUp="SearchTextBox_PreviewMouseUp"
            PreviewKeyDown="SearchTextBox_PreviewKeyDown"
            Text="{Binding RelativeSource={RelativeSource FindAncestor,
                   AncestorType={x:Type controls:SearchControl}},
                   Path=Text, UpdateSourceTrigger=PropertyChanged}"
            />
        
        <Button
            Name="SearchClearButton"
            Background="Transparent"
            HorizontalAlignment="Right"
            FontFamily="Marlett"
            FontSize="10"
            Width="17"
            Height="17"
            Margin="2,0,4,0"
            Visibility="Hidden"
            Command="{Binding RelativeSource={RelativeSource FindAncestor,
                      AncestorType={x:Type controls:SearchControl}}, Path=ClearCommand}"
            >r

            <Button.Resources>
                <Style TargetType="{x:Type Border}">
                    <Setter Property="CornerRadius" Value="3"/>
                </Style>
            </Button.Resources>
            
            <Button.Style>
                <Style TargetType="Button">
                    <Setter Property="Background" Value="{Binding Theme.Background}"/>
                    <Setter Property="Foreground" Value="{Binding Theme.Foreground2}"/>
                    <Setter Property="Template">
                        <Setter.Value>
                            <ControlTemplate TargetType="Button">
                                <Border
                                    BorderThickness="1"
                                    BorderBrush="{TemplateBinding Foreground}"
                                    SnapsToDevicePixels="True"
                                    >
                                    
                                    <ContentPresenter
                                        HorizontalAlignment="Center"
                                        VerticalAlignment="Center"
                                        />
                                </Border>
                            </ControlTemplate>
                        </Setter.Value>
                    </Setter>
                    
                    <Style.Triggers>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter Property="Foreground" Value="{Binding Theme.Heading}"/>
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </Button.Style>
        </Button>
    </Grid>
</UserControl>