<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/TextBox.xaml" />
        <ResourceDictionary Source="pack://application:,,,/BPA.UIControl;component/Themes/ContextMenu.xaml" />
    </ResourceDictionary.MergedDictionaries>

    <Style x:Key="RubyerPasswordBox" TargetType="{x:Type PasswordBox}">
        <Setter Property="PasswordChar" Value="●" />
        <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="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="Padding" Value="0 5" />
        <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.MouseOverBrush" Value="{DynamicResource Primary}" />
        <Setter Property="bpa:ControlHelper.FocusBorderBrush" Value="{DynamicResource Primary}" />
        <Setter Property="bpa:PasswordBoxHelper.ShowSwitchButton" Value="False" />
        <Setter Property="bpa:PasswordBoxHelper.IsBindable" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type PasswordBox}">
                    <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"
                                                VerticalAlignment="Center"
                                                Content="{Binding Path=(bpa:InputBoxHelper.PreContent), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                                Foreground="{DynamicResource SeconarydText}" />

                                <Grid Grid.Column="1" VerticalAlignment="Center">
                                    <ScrollViewer x:Name="PART_ContentHost"
                                                  Margin="-2 0 0 0"
                                                  Padding="{TemplateBinding Padding}"
                                                  Focusable="False"
                                                  HorizontalScrollBarVisibility="Hidden"
                                                  VerticalScrollBarVisibility="Hidden" />

                                    <TextBlock x:Name="showPassword"
                                               IsHitTestVisible="False"
                                               Text="{Binding Path=(bpa:PasswordBoxHelper.BindablePassword), RelativeSource={RelativeSource Mode=TemplatedParent}}"
                                               Visibility="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"
                                        VerticalAlignment="Center"
                                        bpa:ButtonHelper.Shape="Circle"
                                        Focusable="False"
                                        Foreground="{DynamicResource SeconarydText}"
                                        Visibility="Collapsed">
                                    <bpa:Icon Type="CloseLine" />
                                </Button>

                                <Button x:Name="PART_SwitchButton"
                                        Style="{StaticResource TextButton}"
                                        Grid.Column="3"
                                        Padding="2"
                                        bpa:ButtonHelper.Shape="Circle"
                                        Focusable="False"
                                        Foreground="{DynamicResource SeconarydText}"
                                        Visibility="Collapsed">
                                    <bpa:Icon x:Name="switchVisibilityIcon" Type="EyeFill" />
                                </Button>
                            </Grid>
                        </Border>
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter TargetName="border" Property="Opacity" Value="{DynamicResource UnenableOpcity}" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="true">
                            <Setter TargetName="border" Property="BorderBrush" Value="{Binding Path=(bpa:ControlHelper.MouseOverBrush), RelativeSource={RelativeSource Mode=TemplatedParent}}" />
                        </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 Mode=TemplatedParent}}" />
                        </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 Password, RelativeSource={RelativeSource Mode=Self}, Mode=OneWay, 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 Password, RelativeSource={RelativeSource Mode=Self}, Mode=OneWay, Converter={StaticResource IsNullOrEmptyConverter}}" Value="False" />-->
                            </MultiDataTrigger.Conditions>
                            <Setter TargetName="clearButton" Property="Visibility" Value="Visible" />
                        </MultiDataTrigger>
                        <DataTrigger Binding="{Binding Path=(bpa:PasswordBoxHelper.ShowSwitchButton), RelativeSource={RelativeSource Mode=Self}}" Value="True">
                            <Setter TargetName="PART_SwitchButton" Property="Visibility" Value="Visible" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=(bpa:PasswordBoxHelper.BindablePassword), RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource IsNullOrEmptyConverter}}" Value="False">
                            <Setter TargetName="watermark" Property="Visibility" Value="Hidden" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=Password, RelativeSource={RelativeSource Mode=Self}, Converter={StaticResource IsNullOrEmptyConverter}}" Value="False">
                            <Setter TargetName="watermark" Property="Visibility" Value="Hidden" />
                        </DataTrigger>
                        <DataTrigger Binding="{Binding Path=(bpa:PasswordBoxHelper.ShowPassword), RelativeSource={RelativeSource Mode=Self}}" Value="True">
                            <Setter TargetName="switchVisibilityIcon" Property="Type" Value="EyeOffFill" />
                            <Setter TargetName="PART_ContentHost" Property="Visibility" Value="Hidden" />
                            <Setter TargetName="showPassword" Property="Visibility" Value="Visible" />
                        </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>
                    </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>

    <!--  Filled PasswordBox  -->
    <Style x:Key="FilledPasswordBox"
           BasedOn="{StaticResource RubyerPasswordBox}"
           TargetType="{x:Type PasswordBox}">
        <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>
</ResourceDictionary>