<!-- Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. See LICENSE in the project root for license information. -->
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="clr-namespace:ModernWpf.Controls"
    xmlns:primitives="clr-namespace:ModernWpf.Controls.Primitives"
    xmlns:sys="clr-namespace:System;assembly=mscorlib">

    <Thickness x:Key="PasswordBoxTopHeaderMargin">0,0,0,8</Thickness>
    <sys:Double x:Key="PasswordBoxIconFontSize">12</sys:Double>

    <primitives:OrConverter x:Key="OrConverter" />

    <Style x:Key="DefaultPasswordBoxStyle" TargetType="PasswordBox">
        <Setter Property="OverridesDefaultStyle" Value="True" />
        <Setter Property="Foreground" Value="{DynamicResource TextControlForeground}" />
        <Setter Property="Background" Value="{DynamicResource TextControlBackground}" />
        <Setter Property="SelectionBrush" Value="{DynamicResource TextControlSelectionHighlightColor}" />
        <Setter Property="BorderBrush" Value="{DynamicResource TextControlBorderBrush}" />
        <Setter Property="BorderThickness" Value="{DynamicResource TextControlBorderThemeThickness}" />
        <Setter Property="FontFamily" Value="{DynamicResource ContentControlThemeFontFamily}" />
        <Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
        <Setter Property="ScrollViewer.HorizontalScrollBarVisibility" Value="Hidden" />
        <Setter Property="ScrollViewer.VerticalScrollBarVisibility" Value="Hidden" />
        <Setter Property="Padding" Value="{DynamicResource TextControlThemePadding}" />
        <Setter Property="PasswordChar" Value="●" />
        <Setter Property="primitives:ControlHelper.CornerRadius" Value="{DynamicResource ControlCornerRadius}" />
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="primitives:PasswordBoxHelper.IsEnabled" Value="True" />
        <Setter Property="ContextMenu" Value="{DynamicResource TextControlContextMenu}" />
        <Setter Property="local:TextContextMenu.UsingTextContextMenu" Value="True" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="PasswordBox">
                    <ControlTemplate.Resources>
                        <StreamGeometry x:Key="View">M 10 7.5 C 10.514322 7.5 11 7.597656 11.455078 7.792969 C 11.910807 7.988281 12.30957 8.256836 12.651367 8.598633 C 12.993164 8.94043 13.261719 9.339193 13.457031 9.794922 C 13.652344 10.250651 13.75 10.735678 13.75 11.25 C 13.75 11.770834 13.652344 12.257487 13.457031 12.709961 C 13.261719 13.162436 12.993164 13.55957 12.651367 13.901367 C 12.30957 14.243164 11.910807 14.511719 11.455078 14.707031 C 11 14.902344 10.514322 15 10 15 C 9.479166 15 8.992513 14.902344 8.540039 14.707031 C 8.087564 14.511719 7.69043 14.243164 7.348633 13.901367 C 7.006836 13.55957 6.738281 13.162436 6.542969 12.709961 C 6.347656 12.257487 6.25 11.770834 6.25 11.25 C 6.25 10.735678 6.347656 10.250651 6.542969 9.794922 C 6.738281 9.339193 7.006836 8.94043 7.348633 8.598633 C 7.69043 8.256836 8.087564 7.988281 8.540039 7.792969 C 8.992513 7.597656 9.479166 7.5 10 7.5 Z M 10 13.75 C 10.345052 13.75 10.668945 13.684896 10.97168 13.554688 C 11.274414 13.424479 11.539713 13.245443 11.767578 13.017578 C 12 12.789714 12.174479 12.524414 12.304688 12.22168 C 12.434896 11.918945 12.5 11.595053 12.5 11.25 C 12.5 10.904948 12.434896 10.581055 12.304688 10.27832 C 12.174479 9.975586 12 9.710287 11.767578 9.482422 C 11.539713 9.254558 11.274414 9.075521 10.97168 8.945313 C 10.668945 8.815104 10.345052 8.75 10 8.75 C 9.654947 8.75 9.331055 8.815104 9.02832 8.945313 C 8.725586 9.075521 8.460286 9.254558 8.232422 9.482422 C 8 9.710287 7.825521 9.975586 7.695313 10.27832 C 7.565104 10.581055 7.5 10.904948 7.5 11.25 C 7.5 11.595053 7.565104 11.918945 7.695313 12.22168 C 7.825521 12.524414 8 12.789714 8.232422 13.017578 C 8.460286 13.245443 8.725586 13.424479 9.02832 13.554688 C 9.331055 13.684896 9.654947 13.75 10 13.75 Z M 10 2.5 C 10.930989 2.5 11.855469 2.615561 12.773438 2.84668 C 13.691405 3.077801 14.557291 3.417969 15.371094 3.867188 C 16.184895 4.316406 16.922199 4.87142 17.583008 5.532227 C 18.243814 6.193035 18.782551 6.953126 19.199219 7.8125 C 19.459635 8.352865 19.658203 8.911133 19.794922 9.487305 C 19.931641 10.063477 20 10.651042 20 11.25 L 18.75 11.25 C 18.75 10.481771 18.632813 9.76237 18.398438 9.091797 C 18.164063 8.421225 17.840168 7.809245 17.426758 7.255859 C 17.013346 6.702475 16.526691 6.207683 15.966797 5.771484 C 15.4069 5.335287 14.80306 4.967449 14.155273 4.667969 C 13.507486 4.36849 12.828775 4.140625 12.119141 3.984375 C 11.409505 3.828125 10.703125 3.75 10 3.75 C 9.296875 3.75 8.590494 3.828125 7.880859 3.984375 C 7.171224 4.140625 6.492513 4.36849 5.844727 4.667969 C 5.19694 4.967449 4.593099 5.335287 4.033203 5.771484 C 3.473307 6.207683 2.986653 6.702475 2.573242 7.255859 C 2.159831 7.809245 1.835938 8.421225 1.601563 9.091797 C 1.367188 9.76237 1.25 10.481771 1.25 11.25 L 0 11.25 C 0 10.651042 0.068359 10.063477 0.205078 9.487305 C 0.341797 8.911133 0.540365 8.352865 0.800781 7.8125 C 1.217448 6.953126 1.756185 6.193035 2.416992 5.532227 C 3.077799 4.87142 3.815104 4.316406 4.628906 3.867188 C 5.442708 3.417969 6.308594 3.077801 7.226563 2.84668 C 8.144531 2.615561 9.06901 2.5 10 2.5 Z</StreamGeometry>
                    </ControlTemplate.Resources>
                    <Grid SnapsToDevicePixels="True">
                        <Grid.Resources>
                            <Style x:Key="RevealButtonStyle" TargetType="ToggleButton">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="ToggleButton">
                                            <Border
                                                x:Name="ButtonLayoutGrid"
                                                Margin="{DynamicResource TextBoxInnerButtonMargin}"
                                                BorderBrush="{DynamicResource TextControlButtonBorderBrush}"
                                                BorderThickness="{TemplateBinding BorderThickness}"
                                                Background="{DynamicResource TextControlButtonBackground}"
                                                CornerRadius="{TemplateBinding primitives:ControlHelper.CornerRadius}"
                                                SnapsToDevicePixels="True">
                                                <local:FontIconFallback
                                                    x:Name="GlyphElement"
                                                    Foreground="{DynamicResource TextControlButtonForeground}"
                                                    VerticalAlignment="Center"
                                                    HorizontalAlignment="Center"
                                                    FontStyle="Normal"
                                                    FontSize="{DynamicResource PasswordBoxIconFontSize}"
                                                    Data="{StaticResource View}"
                                                    FontFamily="{DynamicResource SymbolThemeFontFamily}" />
                                            </Border>
                                            <ControlTemplate.Triggers>
                                                <Trigger Property="IsMouseOver" Value="True">
                                                    <Setter TargetName="ButtonLayoutGrid" Property="Background" Value="{DynamicResource TextControlButtonBackgroundPointerOver}" />
                                                    <Setter TargetName="ButtonLayoutGrid" Property="BorderBrush" Value="{DynamicResource TextControlButtonBorderBrushPointerOver}" />
                                                    <Setter TargetName="GlyphElement" Property="Foreground" Value="{DynamicResource TextControlButtonForegroundPointerOver}" />
                                                </Trigger>
                                                <Trigger Property="IsPressed" Value="True">
                                                    <Setter TargetName="ButtonLayoutGrid" Property="Background" Value="{DynamicResource TextControlButtonBackgroundPressed}" />
                                                    <Setter TargetName="ButtonLayoutGrid" Property="BorderBrush" Value="{DynamicResource TextControlButtonBorderBrushPressed}" />
                                                    <Setter TargetName="GlyphElement" Property="Foreground" Value="{DynamicResource TextControlButtonForegroundPressed}" />
                                                </Trigger>
                                                <Trigger Property="IsEnabled" Value="False">
                                                    <Setter TargetName="ButtonLayoutGrid" Property="Opacity" Value="0" />
                                                </Trigger>
                                            </ControlTemplate.Triggers>
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                            <Style x:Key="TextBoxStyle" TargetType="TextBox">
                                <Setter Property="Template">
                                    <Setter.Value>
                                        <ControlTemplate TargetType="TextBox">
                                            <ScrollViewer
                                                x:Name="PART_ContentHost"
                                                Style="{DynamicResource TextControlContentHostStyle}"
                                                Focusable="False"
                                                HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                                                VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                                                Margin="{TemplateBinding BorderThickness}"
                                                Padding="{TemplateBinding Padding}"
                                                IsTabStop="False" />
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </Grid.Resources>
                        <VisualStateManager.VisualStateGroups>
                            <VisualStateGroup x:Name="ButtonStates">
                                <VisualState x:Name="ButtonVisible">
                                    <Storyboard>
                                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="RevealButton" Storyboard.TargetProperty="Visibility">
                                            <DiscreteObjectKeyFrame KeyTime="0" Value="{x:Static Visibility.Visible}" />
                                        </ObjectAnimationUsingKeyFrames>
                                    </Storyboard>
                                </VisualState>
                                <VisualState x:Name="ButtonCollapsed" />
                            </VisualStateGroup>
                        </VisualStateManager.VisualStateGroups>
                        <Grid.RowDefinitions>
                            <RowDefinition Height="Auto" />
                            <RowDefinition Height="*" />
                            <RowDefinition Height="Auto" />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="Auto" />
                        </Grid.ColumnDefinitions>
                        <local:ContentPresenterEx
                            x:Name="HeaderContentPresenter"
                            Grid.Row="0"
                            Grid.Column="0"
                            Grid.ColumnSpan="2"
                            Content="{TemplateBinding primitives:ControlHelper.Header}"
                            ContentTemplate="{TemplateBinding primitives:ControlHelper.HeaderTemplate}"
                            FontWeight="Normal"
                            Foreground="{DynamicResource TextControlHeaderForeground}"
                            Margin="{DynamicResource PasswordBoxTopHeaderMargin}"
                            TextWrapping="Wrap"
                            VerticalAlignment="Top"
                            Visibility="{TemplateBinding primitives:ControlHelper.HeaderVisibility}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        <Border
                            x:Name="BorderElement"
                            Grid.Row="1"
                            Grid.Column="0"
                            Grid.RowSpan="1"
                            Grid.ColumnSpan="2"
                            Background="{TemplateBinding Background}"
                            BorderBrush="{TemplateBinding BorderBrush}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            CornerRadius="{TemplateBinding primitives:ControlHelper.CornerRadius}"
                            MinWidth="{DynamicResource TextControlThemeMinWidth}"
                            MinHeight="{DynamicResource TextControlThemeMinHeight}" />
                        <Grid
                            Grid.Row="1"
                            Grid.Column="0">
                            <ScrollViewer
                                x:Name="PART_ContentHost"
                                Style="{DynamicResource TextControlContentHostStyle}"
                                Focusable="False"
                                HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                                VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                                Margin="{TemplateBinding BorderThickness}"
                                Padding="{TemplateBinding Padding}"
                                IsTabStop="False"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                            <TextBox
                                x:Name="TextBox"
                                Style="{StaticResource TextBoxStyle}"
                                Foreground="{TemplateBinding Foreground}"
                                SelectionBrush="{TemplateBinding SelectionBrush}"
                                SelectionOpacity="{TemplateBinding SelectionOpacity}"
                                CaretBrush="{TemplateBinding CaretBrush}"
                                MaxLength="{TemplateBinding MaxLength}"
                                FontFamily="{TemplateBinding FontFamily}"
                                FontSize="{TemplateBinding FontSize}"
                                ScrollViewer.HorizontalScrollBarVisibility="{TemplateBinding ScrollViewer.HorizontalScrollBarVisibility}"
                                ScrollViewer.VerticalScrollBarVisibility="{TemplateBinding ScrollViewer.VerticalScrollBarVisibility}"
                                BorderThickness="{TemplateBinding BorderThickness}"
                                Padding="{TemplateBinding Padding}"
                                ContextMenu="{TemplateBinding ContextMenu}"
                                local:TextContextMenu.UsingTextContextMenu="{TemplateBinding local:TextContextMenu.UsingTextContextMenu}"
                                Visibility="Collapsed"
                                IsTabStop="False"
                                SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                        </Grid>
                        <TextBlock
                            x:Name="PlaceholderTextContentPresenter"
                            Grid.Row="1"
                            Grid.Column="0"
                            Grid.ColumnSpan="2"
                            Foreground="{DynamicResource TextControlPlaceholderForeground}"
                            Margin="{TemplateBinding BorderThickness}"
                            Padding="{TemplateBinding Padding}"
                            Text="{TemplateBinding primitives:ControlHelper.PlaceholderText}"
                            IsHitTestVisible="False"
                            Visibility="{TemplateBinding primitives:PasswordBoxHelper.PlaceholderTextVisibility}" />
                        <ToggleButton
                            x:Name="RevealButton"
                            Grid.Row="1"
                            Grid.Column="1"
                            Style="{StaticResource RevealButtonStyle}"
                            BorderThickness="{TemplateBinding BorderThickness}"
                            primitives:ControlHelper.CornerRadius="{TemplateBinding primitives:ControlHelper.CornerRadius}"
                            Padding="{DynamicResource HelperButtonThemePadding}"
                            IsTabStop="False"
                            Visibility="Collapsed"
                            FontSize="{TemplateBinding FontSize}"
                            VerticalAlignment="Stretch"
                            Width="30"
                            Focusable="False" />
                        <ContentPresenter
                            x:Name="DescriptionPresenter"
                            Grid.Row="2"
                            Grid.Column="0"
                            Grid.ColumnSpan="2"
                            Content="{TemplateBinding primitives:ControlHelper.Description}"
                            TextElement.Foreground="{DynamicResource SystemControlDescriptionTextForegroundBrush}"
                            Visibility="{TemplateBinding primitives:ControlHelper.DescriptionVisibility}"
                            SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" />
                    </Grid>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsEnabled" Value="False">
                            <Setter TargetName="HeaderContentPresenter" Property="Foreground" Value="{DynamicResource TextControlHeaderForegroundDisabled}" />
                            <Setter TargetName="BorderElement" Property="Background" Value="{DynamicResource TextControlBackgroundDisabled}" />
                            <Setter TargetName="BorderElement" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushDisabled}" />
                            <Setter TargetName="TextBox" Property="Background" Value="{DynamicResource TextControlBackgroundDisabled}" />
                            <Setter Property="Foreground" Value="{DynamicResource TextControlForegroundDisabled}" />
                            <Setter TargetName="PlaceholderTextContentPresenter" Property="Foreground" Value="{DynamicResource TextControlPlaceholderForegroundDisabled}" />
                        </Trigger>
                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="BorderElement" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushPointerOver}" />
                            <Setter TargetName="BorderElement" Property="Background" Value="{DynamicResource TextControlBackgroundPointerOver}" />
                            <Setter TargetName="TextBox" Property="Background" Value="{DynamicResource TextControlBackgroundPointerOver}" />
                            <Setter TargetName="PlaceholderTextContentPresenter" Property="Foreground" Value="{DynamicResource TextControlPlaceholderForegroundPointerOver}" />
                            <Setter Property="Foreground" Value="{DynamicResource TextControlForegroundPointerOver}" />
                        </Trigger>
                        <DataTrigger Value="True">
                            <DataTrigger.Binding>
                                <MultiBinding Converter="{StaticResource OrConverter}">
                                    <Binding Path="IsSelectionActive" RelativeSource="{RelativeSource Self}" />
                                    <Binding Path="IsSelectionActive" ElementName="TextBox" />
                                </MultiBinding>
                            </DataTrigger.Binding>
                            <Setter TargetName="PlaceholderTextContentPresenter" Property="Foreground" Value="{DynamicResource TextControlPlaceholderForegroundFocused}" />
                            <Setter TargetName="BorderElement" Property="Background" Value="{DynamicResource TextControlBackgroundFocused}" />
                            <Setter TargetName="BorderElement" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushFocused}" />
                            <Setter TargetName="BorderElement" Property="BorderThickness" Value="{DynamicResource TextControlBorderThemeThicknessFocused}" />
                            <Setter Property="Foreground" Value="{DynamicResource TextControlForegroundFocused}" />
                            <Setter Property="CaretBrush" Value="{DynamicResource TextControlForegroundFocused}" />
                        </DataTrigger>
                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="primitives:PasswordBoxHelper.PasswordRevealMode" Value="Peek" />
                                <Condition SourceName="RevealButton" Property="IsPressed" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_ContentHost" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="TextBox" Property="Visibility" Value="Visible" />
                        </MultiTrigger>
                        <Trigger Property="primitives:PasswordBoxHelper.PasswordRevealMode" Value="Visible">
                            <Setter TargetName="PART_ContentHost" Property="Visibility" Value="Collapsed" />
                            <Setter TargetName="TextBox" Property="Visibility" Value="Visible" />
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

    <Style TargetType="PasswordBox" BasedOn="{StaticResource DefaultPasswordBoxStyle}" />

</ResourceDictionary>