<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:bpa="clr-namespace:BPA.UIControl">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="pack://application:,,,/BPA.UIControl;component/Themes/ContextMenu.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <!--  错误验证  -->
    <ControlTemplate x:Key="RubyerValidationErrorTemplate">
        <StackPanel>
            <AdornedElementPlaceholder Name="Placeholder" />
            <Border x:Name="DefaultErrorViewer"
                    Background="Transparent"
                    Visibility="Visible">
                <TextBlock x:Name="message"
                           MaxWidth="{Binding ElementName=Placeholder, Path=ActualWidth}"
                           Margin="1 -1"
                           HorizontalAlignment="Left"
                           Foreground="{DynamicResource Error}"
                           Text="{Binding CurrentItem.ErrorContent}"
                           TextTrimming="WordEllipsis"
                           ToolTip="{Binding CurrentItem.ErrorContent}">
                    <TextBlock.FontSize>
                        <MultiBinding Converter="{StaticResource MathSubtractConverter}">
                            <Binding Path="FontSize" RelativeSource="{RelativeSource AncestorType=Control}" />
                            <Binding Source="3" />
                        </MultiBinding>
                    </TextBlock.FontSize>
                </TextBlock>
            </Border>
        </StackPanel>
    </ControlTemplate>

    <ControlTemplate x:Key="MouseOverValidationErrorTemplate">
        <Grid>
            <AdornedElementPlaceholder Name="Placeholder" />
            <Polygon HorizontalAlignment="Right"
                     VerticalAlignment="Top"
                     Fill="{DynamicResource Error}"
                     Points="0,0 15,0 15,15"
                     ToolTip="{Binding CurrentItem.ErrorContent}"
                     ToolTipService.InitialShowDelay="1" />
        </Grid>
    </ControlTemplate>

    <!--  默认文本框  -->
    <Style x:Key="RubyerTextBox" TargetType="{x:Type TextBox}">
        <Setter Property="Background" Value="{DynamicResource ControlBackground}" />
        <Setter Property="BorderBrush" Value="{DynamicResource Border}" />
        <Setter Property="Foreground" Value="{DynamicResource DefaultForeground}" />
        <Setter Property="BorderThickness" Value="{DynamicResource DefaultBorderThickness}" />
        <Setter Property="Padding" Value="0 5" />
        <Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
        <Setter Property="HorizontalContentAlignment" Value="Left" />
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="AllowDrop" Value="true" />
        <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst" />
        <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
        <Setter Property="IsInactiveSelectionHighlightEnabled" Value="True" />
        <Setter Property="VerticalContentAlignment" Value="Center" />
        <Setter Property="Cursor" Value="IBeam" />
        <Setter Property="Validation.ErrorTemplate" Value="{StaticResource RubyerValidationErrorTemplate}" />
        <Setter Property="bpa:ControlHelper.CornerRadius" Value="{DynamicResource AllControlCornerRadius}" />
        <Setter Property="bpa:ControlHelper.FocusBorderBrush" Value="{DynamicResource Primary}" />
        <Setter Property="bpa:ControlHelper.MouseOverBrush" Value="{DynamicResource Primary}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type TextBox}">
                    <Grid>
                        <Border x:Name="effectBorder"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{Binding Path=(bpa:ControlHelper.FocusBorderBrush), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                Opacity="0">
                            <Border.Effect>
                                <DropShadowEffect x:Name="shadowEffect"
                                                  BlurRadius="2"
                                                  Direction="0"
                                                  ShadowDepth="0"
                                                  Color="{Binding BorderBrush.Color, ElementName=effectBorder}" />
                            </Border.Effect>
                        </Border>
                        <Border x:Name="border"
                                Background="{TemplateBinding Background}"
                                BorderBrush="{TemplateBinding BorderBrush}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                CornerRadius="{Binding Path=(bpa:ControlHelper.CornerRadius), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                SnapsToDevicePixels="True">
                            <Grid Margin="{Binding Path=(bpa:InputBoxHelper.InternalSpacing), Converter={StaticResource DoubleToLeftAndRightThicknessConverter}, RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                  bpa:GridHelper.ColumnDefinitions="Auto,*,Auto,Auto"
                                  bpa:PanelHelper.Spacing="{Binding Path=(bpa:InputBoxHelper.InternalSpacing), RelativeSource={RelativeSource Mode=TemplatedParent}}">

                                <ContentControl x:Name="preContent"
                                                Grid.Column="0"
                                                Content="{Binding Path=(bpa:InputBoxHelper.PreContent), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                                Foreground="{DynamicResource SeconarydText}" />

                                <Grid Grid.Column="1" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
                                    <ScrollViewer x:Name="PART_ContentHost"
                                                  Margin="-2 0 0 0"
                                                  Padding="{TemplateBinding Padding}"
                                                  Focusable="false"
                                                  HorizontalScrollBarVisibility="Hidden"
                                                  VerticalScrollBarVisibility="Hidden" />
                                    <TextBlock x:Name="watermark"
                                               Foreground="{DynamicResource WatermarkText}"
                                               IsHitTestVisible="False"
                                               Text="{Binding Path=(bpa:InputBoxHelper.Watermark), RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                                </Grid>

                                <Button x:Name="clearButton"
                                        Style="{StaticResource TextButton}"
                                        Grid.Column="2"
                                        Padding="2"
                                        bpa:ButtonHelper.Shape="Circle"
                                        Focusable="False"
                                        Foreground="{DynamicResource SeconarydText}"
                                        Visibility="Collapsed">
                                    <bpa:Icon Type="CloseLine" />
                                </Button>

                                <ContentControl x:Name="postContent"
                                                Grid.Column="3"
                                                Content="{Binding Path=(bpa:InputBoxHelper.PostContent), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                                Foreground="{DynamicResource SeconarydText}" />
                            </Grid>
                        </Border>
                    </Grid>

                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter Property="Opacity" Value="{DynamicResource UnenableOpcity}" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="border" Property="BorderBrush" Value="{Binding Path=(bpa:ControlHelper.MouseOverBrush), RelativeSource={RelativeSource AncestorType=TextBox}}" />
                        </Trigger>
                        <Trigger Property="IsKeyboardFocused" Value="True">
                            <Trigger.EnterActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="effectBorder"
                                                         Storyboard.TargetProperty="Opacity"
                                                         To="1"
                                                         Duration="0:0:0.25" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <BeginStoryboard>
                                    <Storyboard>
                                        <DoubleAnimation Storyboard.TargetName="effectBorder"
                                                         Storyboard.TargetProperty="Opacity"
                                                         Duration="0:0:0.25" />
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.ExitActions>
                            <Setter TargetName="border" Property="BorderBrush" Value="{Binding Path=(bpa:ControlHelper.FocusBorderBrush), RelativeSource={RelativeSource AncestorType=TextBox}}" />
                        </Trigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsKeyboardFocused, RelativeSource={RelativeSource Mode=Self}}" Value="true" />
                                <Condition Binding="{Binding Path=(bpa:InputBoxHelper.IsClearable), RelativeSource={RelativeSource Mode=Self}}" Value="true" />
                                <Condition Binding="{Binding Path=Text, RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource IsNullOrEmptyConverter}}" Value="False" />
                            </MultiDataTrigger.Conditions>
                            <Setter TargetName="clearButton" Property="Visibility" Value="Visible" />
                        </MultiDataTrigger>
                        <MultiDataTrigger>
                            <MultiDataTrigger.Conditions>
                                <Condition Binding="{Binding IsMouseOver, RelativeSource={RelativeSource Mode=Self}}" Value="true" />
                                <Condition Binding="{Binding Path=(bpa:InputBoxHelper.IsClearable), RelativeSource={RelativeSource Mode=Self}}" Value="true" />
                                <Condition Binding="{Binding Path=Text, RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource IsNullOrEmptyConverter}}" Value="False" />
                            </MultiDataTrigger.Conditions>
                            <Setter TargetName="clearButton" Property="Visibility" Value="Visible" />
                        </MultiDataTrigger>
                        <DataTrigger Binding="{Binding Path=Text, RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource IsNullOrEmptyConverter}}" Value="False">
                            <Setter TargetName="watermark" Property="Visibility" Value="Hidden" />
                        </DataTrigger>
                        <Trigger Property="Validation.HasError" Value="True">
                            <Setter TargetName="effectBorder" Property="BorderBrush" Value="{DynamicResource Error}" />
                            <Setter TargetName="border" Property="BorderBrush" Value="{DynamicResource Error}" />
                        </Trigger>
                        <Trigger Property="bpa:InputBoxHelper.IsRound" Value="True">
                            <Setter Property="bpa:ControlHelper.CornerRadius" Value="{Binding ActualHeight, RelativeSource={RelativeSource Self}, Converter={StaticResource HalfOfDoubleConverter}}" />
                        </Trigger>
                        <Trigger Property="BorderThickness" Value="0">
                            <Setter TargetName="effectBorder" Property="Visibility" Value="Collapsed" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Setter Property="ContextMenu">
            <Setter.Value>
                <ContextMenu Style="{StaticResource RubyerContextMenu}">
                    <MenuItem Command="ApplicationCommands.Copy" />
                    <MenuItem Command="ApplicationCommands.Cut" />
                    <MenuItem Command="ApplicationCommands.Paste" />
                </ContextMenu>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <MultiTrigger>
                <MultiTrigger.Conditions>
                    <Condition Property="IsInactiveSelectionHighlightEnabled" Value="true" />
                    <Condition Property="IsSelectionActive" Value="false" />
                </MultiTrigger.Conditions>
                <Setter Property="SelectionBrush" Value="{DynamicResource {x:Static SystemColors.InactiveSelectionHighlightBrushKey}}" />
            </MultiTrigger>
        </Style.Triggers>
    </Style>

    <Style x:Key="LightTextBox"
           BasedOn="{StaticResource RubyerTextBox}"
           TargetType="{x:Type TextBox}">
        <Setter Property="bpa:ControlHelper.FocusBorderBrush" Value="{DynamicResource Light}" />
        <Setter Property="bpa:ControlHelper.MouseOverBrush" Value="{DynamicResource Light}" />
    </Style>

    <Style x:Key="DarkTextBox"
           BasedOn="{StaticResource RubyerTextBox}"
           TargetType="{x:Type TextBox}">
        <Setter Property="bpa:ControlHelper.FocusBorderBrush" Value="{DynamicResource Dark}" />
        <Setter Property="bpa:ControlHelper.MouseOverBrush" Value="{DynamicResource Dark}" />
    </Style>

    <Style x:Key="AccentTextBox"
           BasedOn="{StaticResource RubyerTextBox}"
           TargetType="{x:Type TextBox}">
        <Setter Property="bpa:ControlHelper.FocusBorderBrush" Value="{DynamicResource Accent}" />
        <Setter Property="bpa:ControlHelper.MouseOverBrush" Value="{DynamicResource Accent}" />
    </Style>

    <!--  Filled TextBox  -->
    <Style x:Key="FilledTextBox"
           BasedOn="{StaticResource RubyerTextBox}"
           TargetType="{x:Type TextBox}">
        <Setter Property="Foreground" Value="{DynamicResource DefaultForeground}" />
        <Setter Property="BorderBrush" Value="{DynamicResource BorderLighter}" />
        <Setter Property="Background" Value="{DynamicResource BorderLighter}" />
        <Setter Property="bpa:ControlHelper.MouseOverBrush" Value="{DynamicResource BorderLight}" />
    </Style>

    <Style x:Key="FilledLightTextBox"
           BasedOn="{StaticResource FilledTextBox}"
           TargetType="{x:Type TextBox}">
        <Setter Property="bpa:ControlHelper.FocusBorderBrush" Value="{DynamicResource Light}" />
    </Style>

    <Style x:Key="FilledDarkTextBox"
           BasedOn="{StaticResource FilledTextBox}"
           TargetType="{x:Type TextBox}">
        <Setter Property="bpa:ControlHelper.FocusBorderBrush" Value="{DynamicResource Dark}" />
    </Style>

    <Style x:Key="FilledAccentTextBox"
           BasedOn="{StaticResource FilledTextBox}"
           TargetType="{x:Type TextBox}">
        <Setter Property="bpa:ControlHelper.FocusBorderBrush" Value="{DynamicResource Accent}" />
    </Style>

    <!--  大文本框  -->
    <Style x:Key="BigTextBox"
           BasedOn="{StaticResource RubyerTextBox}"
           TargetType="{x:Type TextBox}">
        <Setter Property="Height" Value="Auto" />
        <Setter Property="AcceptsReturn" Value="True" />
        <Setter Property="Padding" Value="2 4" />
        <Setter Property="TextWrapping" Value="Wrap" />
        <Setter Property="VerticalContentAlignment" Value="Top" />
        <Setter Property="VerticalScrollBarVisibility" Value="Auto" />
        <Setter Property="bpa:ControlHelper.FocusedBrush" Value="{DynamicResource Primary}" />
    </Style>
</ResourceDictionary>