<UserControl
    x:Class="PDF_Office.CustomControl.TextBoxWithTip"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:local="clr-namespace:PDF_Office.CustomControl"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    d:DesignHeight="450"
    d:DesignWidth="800"
    mc:Ignorable="d">
    <UserControl.Style>
        <Style TargetType="{x:Type UserControl}">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate>
                        <Grid>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="*" />
                                <RowDefinition MaxHeight="30" />
                            </Grid.RowDefinitions>
                            <local:TextBoxEx
                                x:Name="TextBox"
                                IsError="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:TextBoxWithTip}, Path=IsError}"
                                PlaceholderText="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:TextBoxWithTip}, Path=PlaceHoldText}"
                                Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:TextBoxWithTip}, Path=Text, UpdateSourceTrigger=PropertyChanged}" />
                            <TextBlock
                                Name="TbTip"
                                Grid.Row="1"
                                Margin="0,2,0,0"
                                FontFamily="Segoe UI"
                                FontSize="12"
                                Foreground="{StaticResource color.field.text.tips}"
                                Text="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:TextBoxWithTip}, Path=TipText}"
                                Visibility="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType=local:TextBoxWithTip}, Path=ShowTip}"
                                TextWrapping="Wrap" />
                        </Grid>
                        <ControlTemplate.Triggers>
                            <Trigger SourceName="TextBox" Property="IsError" Value="True">
                                <Setter TargetName="TbTip" Property="Foreground" Value="{StaticResource color.field.text.tips-error}" />
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    </UserControl.Style>
</UserControl>