Files
ShrlAlgoToolkit/AntdWpf/Styles/PasswordBox.xaml
2025-07-12 23:31:32 +08:00

276 lines
15 KiB
XML

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:AntdWpf.Controls"
xmlns:Behaviors="clr-namespace:AntdWpf.Behaviors"
xmlns:helpers="clr-namespace:AntdWpf.Helpers">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="pack://application:,,,/AntdWpf;component/Styles/Converters.xaml" />
<ResourceDictionary Source="pack://application:,,,/AntdWpf;component/Styles/Animations.xaml" />
<ResourceDictionary Source="pack://application:,,,/AntdWpf;component/Styles/Input.xaml" />
</ResourceDictionary.MergedDictionaries>
<Style x:Key="Ant.Eyeable" TargetType="{x:Type ToggleButton}">
<Setter Property="Opacity" Value="0.65" />
<Setter Property="OverridesDefaultStyle" Value="True" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type ToggleButton}">
<ContentPresenter />
</ControlTemplate>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="IsMouseOver" Value="True">
<Setter Property="Opacity" Value="0.85" />
</Trigger>
<Trigger Property="IsPressed" Value="True">
<Setter Property="Opacity" Value="1" />
</Trigger>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Opacity" Value="1" />
</Trigger>
</Style.Triggers>
</Style>
<ControlTemplate x:Key="Ant.PasswordBoxTemplate" TargetType="{x:Type PasswordBox}">
<Grid>
<!-- Input Effect -->
<Border x:Name="Effect"
Opacity="0"
Focusable="False"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{DynamicResource OutlineThickness}"
CornerRadius="{TemplateBinding helpers:AntdControl.CornerRadius}"
Margin="{Binding BorderThickness, Mode=OneWay, RelativeSource={RelativeSource Self},
Converter={StaticResource ThicknessReverseConverter}}" />
<!-- Input -->
<controls:AntdBorder UseLayoutRounding="True"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
BorderStyle="{TemplateBinding helpers:AntdControl.BorderStyle}"
CornerRadius="{TemplateBinding helpers:AntdControl.CornerRadius}">
<Grid>
<Grid.ColumnDefinitions>
<!-- Prefix -->
<ColumnDefinition Width="Auto" />
<!-- Input -->
<ColumnDefinition Width="*" />
<!-- Suffix -->
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- Prefix -->
<ContentPresenter x:Name="Prefix"
Grid.Column="0"
Margin="1 0 5 0"
Focusable="False"
Content="{TemplateBinding helpers:Input.Prefix}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
<!-- Placeholder -->
<TextBlock x:Name="Placeholder"
Grid.Column="1"
Focusable="False"
Visibility="Collapsed"
Text="{TemplateBinding helpers:Input.Placeholder}"
Foreground="{TemplateBinding helpers:Input.PlaceholderBrush}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />
<!-- Input -->
<!-- ScrollViewer will automatically handle padding, so you need to change the margin to a negative value. -->
<ScrollViewer x:Name="PART_ContentHost"
Grid.Column="1"
IsTabStop="False"
BorderThickness="0"
Background="{x:Null}"
Margin="{Binding Padding, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent},
Converter={StaticResource ThicknessReverseConverter}}" />
<!-- Suffix -->
<ContentPresenter x:Name="Suffix"
Grid.Column="2"
Margin="5 0 1 0"
Focusable="False"
Content="{TemplateBinding helpers:Input.Suffix}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Grid>
</controls:AntdBorder>
<VisualStateManager.VisualStateGroups>
<VisualStateGroup x:Name="FocusStates">
<VisualStateGroup.Transitions>
<VisualTransition GeneratedDuration="0:0:0.3" />
</VisualStateGroup.Transitions>
<VisualState x:Name="Focused" Storyboard="{StaticResource Ant.InputAnimating}" />
<VisualState x:Name="Unfocused" />
</VisualStateGroup>
</VisualStateManager.VisualStateGroups>
</Grid>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding Path=(helpers:Input.Password), Mode=OneWay, RelativeSource={RelativeSource Self}}" Value="">
<Setter TargetName="Placeholder" Property="Visibility" Value="Visible" />
</DataTrigger>
<!-- Prefix & Suffix -->
<Trigger SourceName="Prefix" Property="Content" Value="{x:Null}">
<Setter TargetName="Prefix" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger SourceName="Suffix" Property="Content" Value="{x:Null}">
<Setter TargetName="Suffix" Property="Visibility" Value="Collapsed" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="helpers:Input.Clearable" Value="True" />
<Condition SourceName="Placeholder" Property="Visibility" Value="Collapsed" />
</MultiTrigger.Conditions>
<Setter TargetName="Suffix" Property="Content">
<!--
How to customize Icon?
By setting up the locally-defined resource dictionary.
-->
<Setter.Value>
<controls:Icon Style="{StaticResource Ant.Clearable}" Type="close" helpers:Input.ClearEnabled="True" />
</Setter.Value>
</Setter>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="Ant.PasswordBoxEyeableTemplate" TargetType="{x:Type PasswordBox}">
<Grid>
<!-- Input Effect -->
<Border x:Name="Effect"
Opacity="0"
Focusable="False"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{DynamicResource OutlineThickness}"
CornerRadius="{TemplateBinding helpers:AntdControl.CornerRadius}"
Margin="{Binding BorderThickness, Mode=OneWay, RelativeSource={RelativeSource Self},
Converter={StaticResource ThicknessReverseConverter}}" />
<!-- Input -->
<controls:AntdBorder UseLayoutRounding="True"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
BorderStyle="{TemplateBinding helpers:AntdControl.BorderStyle}"
CornerRadius="{TemplateBinding helpers:AntdControl.CornerRadius}">
<Grid>
<Grid.ColumnDefinitions>
<!-- Prefix -->
<ColumnDefinition Width="Auto" />
<!-- Input -->
<ColumnDefinition Width="*" />
<!-- Eye -->
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- Prefix -->
<ContentPresenter x:Name="Prefix"
Grid.Column="0"
Focusable="False"
Margin="1 0 5 0"
Content="{TemplateBinding helpers:Input.Prefix}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
<!-- Placeholder -->
<TextBlock x:Name="Placeholder"
Grid.Column="1"
Focusable="False"
Visibility="Collapsed"
Text="{TemplateBinding helpers:Input.Placeholder}"
Foreground="{TemplateBinding helpers:Input.PlaceholderBrush}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" />
<!-- Input -->
<!-- ScrollViewer will automatically handle padding, so you need to change the margin to a negative value. -->
<ScrollViewer x:Name="PART_ContentHost"
Grid.Column="1"
IsTabStop="False"
BorderThickness="0"
Background="{x:Null}"
Margin="{Binding Padding, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent},
Converter={StaticResource ThicknessReverseConverter}}" />
<!-- Password Text Box -->
<TextBox x:Name="PART_TextBox"
Grid.Column="1"
IsTabStop="False"
Visibility="Collapsed"
Style="{StaticResource Ant.EditableTextBox}"
Text="{Binding Path=(helpers:Input.Password), Mode=TwoWay,
RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}" />
<!-- Eye -->
<ToggleButton x:Name="PART_Eye"
Grid.Column="2"
Margin="5 0 1 0"
IsTabStop="False"
Focusable="False"
Visibility="Collapsed"
Style="{StaticResource Ant.Eyeable}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<!--
How to customize Icon?
By setting up the locally-defined resource dictionary.
-->
<controls:Icon Type="eye" />
</ToggleButton>
</Grid>
</controls:AntdBorder>
</Grid>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding Path=(helpers:Input.Password), Mode=OneWay, RelativeSource={RelativeSource Self}}" Value="">
<Setter TargetName="Placeholder" Property="Visibility" Value="Visible" />
</DataTrigger>
<!-- Prefix -->
<Trigger SourceName="Prefix" Property="Content" Value="{x:Null}">
<Setter TargetName="Prefix" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger SourceName="Placeholder" Property="Visibility" Value="Collapsed">
<Setter TargetName="PART_Eye" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger SourceName="PART_TextBox" Property="IsFocused" Value="True">
<Setter Property="BorderBrush" Value="{DynamicResource OutlineBrush}" />
</Trigger>
<Trigger SourceName="PART_Eye" Property="IsChecked" Value="True">
<Setter TargetName="PART_TextBox" Property="Visibility" Value="Visible" />
<Setter TargetName="PART_ContentHost" Property="Visibility" Value="Collapsed" />
</Trigger>
<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="Effect"
Storyboard.TargetProperty="Opacity"
Duration="0:0:0.3"
To="0.2" />
</Storyboard>
</BeginStoryboard>
</Trigger.EnterActions>
<Trigger.ExitActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation Storyboard.TargetName="Effect"
Storyboard.TargetProperty="Opacity"
Duration="0:0:0.3" />
</Storyboard>
</BeginStoryboard>
</Trigger.ExitActions>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style x:Key="Ant.PasswordBox" BasedOn="{StaticResource Ant.Input}" TargetType="{x:Type PasswordBox}">
<Setter Property="Template" Value="{StaticResource Ant.PasswordBoxTemplate}" />
<Setter Property="Behaviors:StylizedBehaviors.Behaviors">
<Setter.Value>
<Behaviors:StylizedBehaviorCollection>
<Behaviors:PasswordBoxBehavior />
</Behaviors:StylizedBehaviorCollection>
</Setter.Value>
</Setter>
<Style.Triggers>
<Trigger Property="helpers:Input.Eyeable" Value="True">
<Setter Property="Template" Value="{StaticResource Ant.PasswordBoxEyeableTemplate}" />
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>