功能完善
This commit is contained in:
315
NeuWPF/NeoUI/Controls/PasswordBoxStyle.xaml
Normal file
315
NeuWPF/NeoUI/Controls/PasswordBoxStyle.xaml
Normal file
@@ -0,0 +1,315 @@
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:assists="clr-namespace:NeumUI.Assists"
|
||||
xmlns:controls="clr-namespace:NeumUI.Controls"
|
||||
xmlns:conv="clr-namespace:NeumUI.Converters"
|
||||
xmlns:svd="clr-namespace:NeumUI.Controls.Decorations"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
|
||||
<!--<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/NeuWPF;component/Controls/TextBoxStyle.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>-->
|
||||
|
||||
<ControlTemplate TargetType="{x:Type PasswordBox}" x:Key="PasswordBoxTemplate">
|
||||
<ControlTemplate.Resources>
|
||||
<!-- 聚焦对象 -->
|
||||
<Storyboard x:Key="TextBox.FocusEffect">
|
||||
<DoubleAnimation
|
||||
Duration="0:0:0.2"
|
||||
Storyboard.TargetName="slot"
|
||||
Storyboard.TargetProperty="Intensity"
|
||||
To="0.5" />
|
||||
</Storyboard>
|
||||
<!-- 取消聚焦对象 -->
|
||||
<Storyboard x:Key="TextBox.LeaveEffect">
|
||||
<DoubleAnimation
|
||||
Duration="0:0:0.2"
|
||||
Storyboard.TargetName="slot"
|
||||
Storyboard.TargetProperty="Intensity"
|
||||
To="0.2" />
|
||||
</Storyboard>
|
||||
</ControlTemplate.Resources>
|
||||
|
||||
<svd:SlotBorder
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Intensity="0.2"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
SnapsToDevicePixels="True"
|
||||
x:Name="slot">
|
||||
<ScrollViewer
|
||||
Focusable="false"
|
||||
Grid.Column="1"
|
||||
HorizontalScrollBarVisibility="Hidden"
|
||||
VerticalScrollBarVisibility="Hidden"
|
||||
x:Name="PART_ContentHost" />
|
||||
</svd: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 Property="ShaderEnabled" TargetName="slot" Value="False" />
|
||||
</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 TargetType="{x:Type PasswordBox}" x:Key="PasswordBoxEyeableTemplate">
|
||||
<ControlTemplate.Resources>
|
||||
<!-- 聚焦对象 -->
|
||||
<Storyboard x:Key="TextBox.FocusEffect">
|
||||
<DoubleAnimation
|
||||
Duration="0:0:0.2"
|
||||
Storyboard.TargetName="slot"
|
||||
Storyboard.TargetProperty="Intensity"
|
||||
To="0.5" />
|
||||
</Storyboard>
|
||||
<!-- 取消聚焦对象 -->
|
||||
<Storyboard x:Key="TextBox.LeaveEffect">
|
||||
<DoubleAnimation
|
||||
Duration="0:0:0.2"
|
||||
Storyboard.TargetName="slot"
|
||||
Storyboard.TargetProperty="Intensity"
|
||||
To="0.2" />
|
||||
</Storyboard>
|
||||
</ControlTemplate.Resources>
|
||||
<Grid>
|
||||
<svd:SlotBorder
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
Intensity="0.2"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
SnapsToDevicePixels="True"
|
||||
UseLayoutRounding="True"
|
||||
x:Name="slot">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<!-- Prefix -->
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<!-- Input -->
|
||||
<ColumnDefinition Width="*" />
|
||||
<!-- Clear -->
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<!-- Eye -->
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<!-- Prefix -->
|
||||
<ContentPresenter
|
||||
Content="{TemplateBinding assists:InputAssist.Prefix}"
|
||||
Focusable="False"
|
||||
Grid.Column="0"
|
||||
Margin="1,0,5,0"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
x:Name="Prefix" />
|
||||
<!-- Placeholder -->
|
||||
<TextBlock
|
||||
Focusable="False"
|
||||
Foreground="{TemplateBinding assists:InputAssist.PlaceholderBrush}"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
Margin="5,0,0,0"
|
||||
Text="{TemplateBinding assists:InputAssist.Placeholder}"
|
||||
VerticalAlignment="Center"
|
||||
Visibility="Collapsed"
|
||||
x:Name="Placeholder" />
|
||||
<!-- Input -->
|
||||
<!-- ScrollViewer will automatically handle padding, so you need to change the margin to a negative value. -->
|
||||
<ScrollViewer
|
||||
Background="{x:Null}"
|
||||
BorderThickness="0"
|
||||
Grid.Column="1"
|
||||
IsTabStop="False"
|
||||
x:Name="PART_ContentHost" />
|
||||
<!-- Password Text Box -->
|
||||
<TextBox
|
||||
Background="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Background}"
|
||||
Grid.Column="1"
|
||||
IsTabStop="False"
|
||||
Style="{DynamicResource FlattenTextBox}"
|
||||
Text="{Binding Path=(assists:InputAssist.Password), Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}"
|
||||
Visibility="Collapsed"
|
||||
x:Name="PART_TextBox" />
|
||||
<!-- 清空按钮 -->
|
||||
<controls:SymbolIcon
|
||||
Grid.Column="2"
|
||||
Style="{DynamicResource ToolIcon}"
|
||||
Symbol="Close"
|
||||
VerticalAlignment="Center"
|
||||
Visibility="Collapsed"
|
||||
x:Name="CloseIcon" />
|
||||
<!-- Eye -->
|
||||
<ToggleButton
|
||||
Grid.Column="3"
|
||||
IsHitTestVisible="True"
|
||||
IsTabStop="False"
|
||||
Margin="5,0,1,0"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
Visibility="Collapsed"
|
||||
x:Name="PART_Eye">
|
||||
<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:SymbolIcon
|
||||
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>
|
||||
</ControlTemplate>
|
||||
</Setter.Value>
|
||||
</Setter>
|
||||
</Style>
|
||||
</ToggleButton.Style>
|
||||
</ToggleButton>
|
||||
|
||||
</Grid>
|
||||
</svd: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 Property="Visibility" TargetName="Placeholder" Value="Visible" />
|
||||
</Trigger>
|
||||
<Trigger Property="IsEnabled" Value="False">
|
||||
<Setter Property="Foreground" Value="{DynamicResource TextDisabledBrush}" />
|
||||
<Setter Property="Background" Value="{DynamicResource ControlBackgroundDisabledBrush}" />
|
||||
<Setter Property="ShaderEnabled" TargetName="slot" Value="False" />
|
||||
</Trigger>
|
||||
<!-- Prefix -->
|
||||
<Trigger Property="Content" SourceName="Prefix" Value="{x:Null}">
|
||||
<Setter Property="Visibility" TargetName="Prefix" Value="Collapsed" />
|
||||
</Trigger>
|
||||
<Trigger Property="Visibility" SourceName="Placeholder" Value="Collapsed">
|
||||
<Setter Property="Visibility" TargetName="PART_Eye" Value="Visible" />
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<!-- 可清空 -->
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="assists:InputAssist.Clearable" Value="True" />
|
||||
<Condition Property="assists:InputAssist.HasPassword" Value="True" />
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Visibility" TargetName="CloseIcon" Value="Visible" />
|
||||
<Setter Property="assists:InputAssist.ClearEnabled" TargetName="CloseIcon" Value="True" />
|
||||
</MultiTrigger>
|
||||
<!--<Trigger SourceName="PART_TextBox" Property="IsFocused" Value="True">
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource PrimaryNormalBrush}" />
|
||||
</Trigger>-->
|
||||
<Trigger Property="IsChecked" SourceName="PART_Eye" Value="True">
|
||||
<Setter Property="Visibility" TargetName="PART_TextBox" Value="Visible" />
|
||||
<Setter Property="Visibility" TargetName="PART_ContentHost" 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 TargetType="PasswordBox">
|
||||
<Setter Property="PasswordChar" Value="●" />
|
||||
<Setter Property="Background" Value="{DynamicResource BackgroundContainerBrush}" />
|
||||
<Setter Property="BorderBrush" Value="Transparent" />
|
||||
<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="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}" />
|
||||
<!-- <Setter Property="Behaviors:StylizedBehaviors.Behaviors"> -->
|
||||
<!-- <Setter.Value> -->
|
||||
<!-- <Behaviors:StylizedBehaviorCollection> -->
|
||||
<!-- <Behaviors:PasswordBoxBehavior /> -->
|
||||
<!-- </Behaviors:StylizedBehaviorCollection> -->
|
||||
<!-- </Setter.Value> -->
|
||||
<!-- </Setter> -->
|
||||
<Style.Triggers>
|
||||
<Trigger Property="assists:InputAssist.Eyeable" Value="True">
|
||||
<Setter Property="Template" Value="{StaticResource PasswordBoxEyeableTemplate}" />
|
||||
</Trigger>
|
||||
</Style.Triggers>
|
||||
</Style>
|
||||
</ResourceDictionary>
|
||||
Reference in New Issue
Block a user