Files
Shrlalgo.RvKits/Melskin/Controls/PasswordBox.xaml
2026-02-20 15:31:44 +08:00

542 lines
30 KiB
XML

<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:assists="clr-namespace:Melskin.Assists"
xmlns:controls="clr-namespace:Melskin.Controls"
xmlns:decorations="clr-namespace:Melskin.Controls.Decorations">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/Melskin;component/Themes/Animations.xaml" />
<ResourceDictionary Source="/Melskin;component/Controls/IconElement.xaml" />
</ResourceDictionary.MergedDictionaries>
<ControlTemplate x:Key="SlotPasswordBoxTemplate" TargetType="{x:Type PasswordBox}">
<decorations:SlotBorder
x:Name="slot"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Intensity="0.2"
SnapsToDevicePixels="True">
<Grid>
<TextBlock
x:Name="Placeholder"
Margin="5,0,0,0"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="Center"
Focusable="False"
Foreground="{DynamicResource TextPlaceholderBrush}"
Text="{TemplateBinding assists:InputAssist.PlaceholderText}"
Visibility="Collapsed" />
<ScrollViewer
x:Name="PART_ContentHost"
Focusable="False"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Hidden" />
</Grid>
</decorations:SlotBorder>
<ControlTemplate.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>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
<Setter TargetName="slot" Property="ShaderEnabled" Value="False" />
</Trigger>
<Trigger Property="assists:InputAssist.HasPassword" Value="False">
<Setter TargetName="Placeholder" Property="Visibility" Value="Visible" />
</Trigger>
<!--<Trigger Property="IsMouseOver" Value="True" />-->
<!--<Trigger Property="IsKeyboardFocused" Value="True" />-->
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="False" />
<Condition Property="IsKeyboardFocused" Value="False" />
</MultiTrigger.Conditions>
<MultiTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource TextBox.LeaveEffect}" />
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource TextBox.FocusEffect}" />
</MultiTrigger.ExitActions>
</MultiTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="SlotPasswordBoxEyeableTemplate" TargetType="{x:Type PasswordBox}">
<ControlTemplate.Resources>
<!-- 聚焦对象 -->
<Storyboard x:Key="TextBox.FocusEffect">
<DoubleAnimation
Storyboard.TargetName="slot"
Storyboard.TargetProperty="Intensity"
To="0.5"
Duration="0:0:0.2" />
</Storyboard>
<!-- 取消聚焦对象 -->
<Storyboard x:Key="TextBox.LeaveEffect">
<DoubleAnimation
Storyboard.TargetName="slot"
Storyboard.TargetProperty="Intensity"
To="0.2"
Duration="0:0:0.2" />
</Storyboard>
</ControlTemplate.Resources>
<Grid>
<decorations:SlotBorder
x:Name="slot"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
Intensity="0.2"
SnapsToDevicePixels="True"
UseLayoutRounding="True">
<Grid>
<Grid.ColumnDefinitions>
<!-- Prefix -->
<ColumnDefinition Width="Auto" />
<!-- Input -->
<ColumnDefinition Width="*" />
<!-- Clear -->
<ColumnDefinition Width="Auto" />
<!-- Eye -->
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- Prefix -->
<ContentPresenter
x:Name="Prefix"
Grid.Column="0"
Margin="1,0,5,0"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding assists:InputAssist.Prefix}"
Focusable="False" />
<!-- Placeholder -->
<TextBlock
x:Name="Placeholder"
Grid.Column="1"
Margin="5,0,0,0"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="Center"
Focusable="False"
Foreground="{DynamicResource TextPlaceholderBrush}"
Text="{TemplateBinding assists:InputAssist.PlaceholderText}"
Visibility="Collapsed" />
<!-- 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"
Background="{x:Null}"
BorderThickness="0"
IsTabStop="False" />
<!-- Password Text Box -->
<TextBox
x:Name="PART_TextBox"
Grid.Column="1"
Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}"
IsTabStop="False"
Style="{DynamicResource FlattenTextBoxStyle}"
Text="{Binding Path=(assists:InputAssist.Password), Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}"
Visibility="Collapsed" />
<!-- 清空按钮 -->
<controls:IconElement
x:Name="CloseIcon"
Grid.Column="2"
Style="{DynamicResource ToolIcon}"
Symbol="Close"
Visibility="Collapsed" />
<!-- Eye -->
<ToggleButton
x:Name="PART_Eye"
Grid.Column="3"
Margin="5,0,1,0"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
IsHitTestVisible="True"
IsTabStop="False"
Visibility="Collapsed">
<ToggleButton.Style>
<Style 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}">
<!--<controls:IconElement
Style="{DynamicResource ToolIcon}"
Symbol="Password2Off"
x:Name="Icon" />
<ControlTemplate.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" />
<Setter Property="Symbol" TargetName="Icon" Value="Password2" />
</Trigger>
</ControlTemplate.Triggers>-->
<controls:IconElement
x:Name="EyeIcon"
VerticalAlignment="Center"
Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType=ToggleButton}}">
<controls:IconElement.Style>
<Style BasedOn="{StaticResource IconElementStyle}" TargetType="{x:Type controls:IconElement}">
<Setter Property="Symbol" Value="Visibility" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, RelativeSource={RelativeSource AncestorType=ToggleButton}}" Value="True">
<Setter Property="Symbol" Value="VisibilityOff" />
</DataTrigger>
</Style.Triggers>
</Style>
</controls:IconElement.Style>
</controls:IconElement>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Opacity" Value="1" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ToggleButton.Style>
</ToggleButton>
</Grid>
</decorations:SlotBorder>
</Grid>
<ControlTemplate.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>
<Trigger Property="assists:InputAssist.HasPassword" Value="False">
<Setter TargetName="Placeholder" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
<Setter TargetName="slot" Property="ShaderEnabled" Value="False" />
</Trigger>
<!-- 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>
<MultiTrigger>
<!-- 可清空 -->
<MultiTrigger.Conditions>
<Condition Property="assists:InputAssist.Clearable" Value="True" />
<Condition Property="assists:InputAssist.HasPassword" Value="True" />
</MultiTrigger.Conditions>
<Setter TargetName="CloseIcon" Property="Visibility" Value="Visible" />
<Setter TargetName="CloseIcon" Property="assists:InputAssist.ClearEnabled" Value="True" />
</MultiTrigger>
<!--<Trigger SourceName="PART_TextBox" Property="IsFocused" Value="True">
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryNormalBrush}" />
</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>
<MultiTrigger>
<MultiTrigger.Conditions>
<Condition Property="IsMouseOver" Value="False" />
<Condition Property="IsKeyboardFocused" Value="False" />
</MultiTrigger.Conditions>
<MultiTrigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource TextBox.LeaveEffect}" />
</MultiTrigger.EnterActions>
<MultiTrigger.ExitActions>
<BeginStoryboard Storyboard="{StaticResource TextBox.FocusEffect}" />
</MultiTrigger.ExitActions>
</MultiTrigger>
<!--<Trigger Property="IsKeyboardFocusWithin" Value="True">
<Trigger.EnterActions>
<BeginStoryboard>
<Storyboard>
<DoubleAnimation
Storyboard.TargetName="Effect"
Storyboard.TargetProperty="Opacity"
To="0.2"
Duration="0:0:0.3" />
</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="SlotPasswordBoxStyle" TargetType="PasswordBox">
<Setter Property="PasswordChar" Value="●" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="assists:InputAssist.PlaceholderText" Value="请输入密码..." />
<Setter Property="FontSize" Value="14" />
<Setter Property="Padding" Value="2" />
<Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<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="ContextMenu" Value="{DynamicResource TextBoxContextMenu}" />
<Setter Property="Template" Value="{StaticResource SlotPasswordBoxTemplate}" />
<Style.Triggers>
<Trigger Property="assists:InputAssist.IsPasswordVisible" Value="True">
<Setter Property="Template" Value="{StaticResource SlotPasswordBoxEyeableTemplate}" />
</Trigger>
</Style.Triggers>
</Style>
<ControlTemplate x:Key="PasswordBoxTemplate" TargetType="{x:Type PasswordBox}">
<Border
x:Name="Border"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding assists:ControlAssist.CornerRadius}"
SnapsToDevicePixels="True">
<Grid>
<TextBlock
x:Name="Placeholder"
Margin="5,0,0,0"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="Center"
Focusable="False"
Foreground="{DynamicResource TextPlaceholderBrush}"
Text="{TemplateBinding assists:InputAssist.PlaceholderText}"
Visibility="Collapsed" />
<ScrollViewer
x:Name="PART_ContentHost"
Focusable="False"
HorizontalScrollBarVisibility="Hidden"
VerticalScrollBarVisibility="Hidden" />
</Grid>
</Border>
<ControlTemplate.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>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
<Setter Property="Cursor" Value="None" />
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource PrimaryNormalBrush}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Border" Property="Background" Value="{DynamicResource ControlBackgroundHoverBrush}" />
</Trigger>
<Trigger Property="assists:InputAssist.HasPassword" Value="False">
<Setter TargetName="Placeholder" Property="Visibility" Value="Visible" />
</Trigger>
<!--<Trigger Property="IsKeyboardFocused" Value="True" />-->
</ControlTemplate.Triggers>
</ControlTemplate>
<ControlTemplate x:Key="PasswordBoxEyeableTemplate" TargetType="{x:Type PasswordBox}">
<Grid>
<Border
x:Name="Border"
Padding="{TemplateBinding Padding}"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding assists:ControlAssist.CornerRadius}"
SnapsToDevicePixels="True"
UseLayoutRounding="True">
<Grid>
<Grid.ColumnDefinitions>
<!-- Prefix -->
<ColumnDefinition Width="Auto" />
<!-- Input -->
<ColumnDefinition Width="*" />
<!-- Eye -->
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<!-- Prefix -->
<ContentPresenter
x:Name="Prefix"
Grid.Column="0"
Margin="1,0,5,0"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Content="{TemplateBinding assists:InputAssist.Prefix}"
Focusable="False" />
<!-- Placeholder -->
<TextBlock
x:Name="Placeholder"
Grid.Column="1"
Margin="5,0,0,0"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="Center"
Focusable="False"
Foreground="{DynamicResource TextPlaceholderBrush}"
Text="{TemplateBinding assists:InputAssist.PlaceholderText}"
Visibility="Collapsed" />
<!-- 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"
Background="{x:Null}"
BorderThickness="0"
IsTabStop="False" />
<!-- Password Text Box -->
<TextBox
x:Name="PART_TextBox"
Grid.Column="1"
Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}"
IsTabStop="False"
Style="{DynamicResource FlattenTextBoxStyle}"
Text="{Binding Path=(assists:InputAssist.Password), Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}"
Visibility="Collapsed" />
<!-- Eye -->
<ToggleButton
x:Name="PART_Eye"
Grid.Column="2"
Margin="5,0,1,0"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
IsHitTestVisible="True"
IsTabStop="False"
Visibility="Collapsed">
<ToggleButton.Style>
<Style 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}">
<controls:IconElement
x:Name="EyeIcon"
VerticalAlignment="Center"
Foreground="{Binding Path=Foreground, RelativeSource={RelativeSource AncestorType=ToggleButton}}">
<controls:IconElement.Style>
<Style BasedOn="{StaticResource IconElementStyle}" TargetType="{x:Type controls:IconElement}">
<Setter Property="Symbol" Value="Visibility" />
<Style.Triggers>
<DataTrigger Binding="{Binding IsChecked, RelativeSource={RelativeSource AncestorType=ToggleButton}}" Value="True">
<Setter Property="Symbol" Value="VisibilityOff" />
</DataTrigger>
</Style.Triggers>
</Style>
</controls:IconElement.Style>
</controls:IconElement>
<ControlTemplate.Triggers>
<Trigger Property="IsChecked" Value="True">
<Setter Property="Opacity" Value="1" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ToggleButton.Style>
</ToggleButton>
</Grid>
</Border>
</Grid>
<ControlTemplate.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>
<Trigger Property="assists:InputAssist.HasPassword" Value="False">
<Setter TargetName="Placeholder" Property="Visibility" Value="Visible" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
<Setter Property="Cursor" Value="None" />
</Trigger>
<!-- 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 Property="IsFocused" Value="True">
<Setter TargetName="Border" Property="BorderBrush" Value="{DynamicResource PrimaryNormalBrush}" />
</Trigger>
<Trigger Property="IsMouseOver" Value="True">
<Setter TargetName="Border" Property="Background" Value="{DynamicResource ControlBackgroundHoverBrush}" />
</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>
</ControlTemplate.Triggers>
</ControlTemplate>
<Style TargetType="PasswordBox">
<Setter Property="PasswordChar" Value="●" />
<Setter Property="Background" Value="{DynamicResource ControlBackgroundNormalBrush}" />
<Setter Property="BorderBrush" Value="Transparent" />
<Setter Property="assists:InputAssist.PlaceholderText" Value="请输入密码" />
<Setter Property="Foreground" Value="{DynamicResource TextPrimaryBrush}" />
<Setter Property="BorderThickness" Value="1" />
<Setter Property="FontSize" Value="14" />
<Setter Property="Padding" Value="3" />
<Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
<Setter Property="HorizontalContentAlignment" Value="Left" />
<Setter Property="VerticalContentAlignment" Value="Center" />
<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="ContextMenu" Value="{DynamicResource TextBoxContextMenu}" />
<Setter Property="Template" Value="{StaticResource PasswordBoxTemplate}" />
<Style.Triggers>
<Trigger Property="assists:InputAssist.IsPasswordVisible" Value="True">
<Setter Property="Template" Value="{StaticResource PasswordBoxEyeableTemplate}" />
</Trigger>
</Style.Triggers>
</Style>
</ResourceDictionary>