月更
This commit is contained in:
294
AntDesignWPF/Controls/PasswordBox.xaml
Normal file
294
AntDesignWPF/Controls/PasswordBox.xaml
Normal file
@@ -0,0 +1,294 @@
|
||||
<ResourceDictionary
|
||||
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
|
||||
xmlns:Behaviors="clr-namespace:AntDesignWPF.Behaviors"
|
||||
xmlns:controls="clr-namespace:AntDesignWPF.Controls"
|
||||
xmlns:helpers="clr-namespace:AntDesignWPF.Helpers"
|
||||
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
|
||||
|
||||
<ResourceDictionary.MergedDictionaries>
|
||||
<ResourceDictionary Source="pack://application:,,,/AntDesignWPF;component/Themes/Converters.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/AntDesignWPF;component/Themes/Animations.xaml" />
|
||||
<ResourceDictionary Source="pack://application:,,,/AntDesignWPF;component/Controls/Input.xaml" />
|
||||
</ResourceDictionary.MergedDictionaries>
|
||||
|
||||
<Style TargetType="{x:Type ToggleButton}" x:Key="Ant.Eyeable">
|
||||
<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 TargetType="{x:Type PasswordBox}" x:Key="Ant.PasswordBoxTemplate">
|
||||
<Grid>
|
||||
<!-- Input Effect -->
|
||||
<Border
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{DynamicResource OutlineThickness}"
|
||||
CornerRadius="{TemplateBinding helpers:AntControl.CornerRadius}"
|
||||
Focusable="False"
|
||||
Margin="{Binding BorderThickness, Mode=OneWay, RelativeSource={RelativeSource Self}, Converter={StaticResource ThicknessReverseConverter}}"
|
||||
Opacity="0"
|
||||
x:Name="Effect" />
|
||||
<!-- Input -->
|
||||
<controls:AntBorder
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderStyle="{TemplateBinding helpers:AntControl.BorderStyle}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="{TemplateBinding helpers:AntControl.CornerRadius}"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
UseLayoutRounding="True">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<!-- Prefix -->
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<!-- Input -->
|
||||
<ColumnDefinition Width="*" />
|
||||
<!-- Suffix -->
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<!-- Prefix -->
|
||||
<ContentPresenter
|
||||
Content="{TemplateBinding helpers:Input.Prefix}"
|
||||
Focusable="False"
|
||||
Grid.Column="0"
|
||||
Margin="1,0,5,0"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
x:Name="Prefix" />
|
||||
<!-- Placeholder -->
|
||||
<TextBlock
|
||||
Focusable="False"
|
||||
Foreground="{TemplateBinding helpers:Input.PlaceholderBrush}"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
Text="{TemplateBinding helpers:Input.Placeholder}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
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"
|
||||
Margin="{Binding Padding, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ThicknessReverseConverter}}"
|
||||
x:Name="PART_ContentHost" />
|
||||
<!-- Suffix -->
|
||||
<ContentPresenter
|
||||
Content="{TemplateBinding helpers:Input.Suffix}"
|
||||
Focusable="False"
|
||||
Grid.Column="2"
|
||||
Margin="5,0,1,0"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
x:Name="Suffix" />
|
||||
</Grid>
|
||||
</controls:AntBorder>
|
||||
<VisualStateManager.VisualStateGroups>
|
||||
<VisualStateGroup x:Name="FocusStates">
|
||||
<VisualStateGroup.Transitions>
|
||||
<VisualTransition GeneratedDuration="0:0:0.3" />
|
||||
</VisualStateGroup.Transitions>
|
||||
<VisualState Storyboard="{StaticResource Ant.InputAnimating}" x:Name="Focused" />
|
||||
<VisualState x:Name="Unfocused" />
|
||||
</VisualStateGroup>
|
||||
</VisualStateManager.VisualStateGroups>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding Path=(helpers:Input.Password), Mode=OneWay, RelativeSource={RelativeSource Self}}" Value="">
|
||||
<Setter Property="Visibility" TargetName="Placeholder" Value="Visible" />
|
||||
</DataTrigger>
|
||||
<!-- Prefix & Suffix -->
|
||||
<Trigger Property="Content" SourceName="Prefix" Value="{x:Null}">
|
||||
<Setter Property="Visibility" TargetName="Prefix" Value="Collapsed" />
|
||||
</Trigger>
|
||||
<Trigger Property="Content" SourceName="Suffix" Value="{x:Null}">
|
||||
<Setter Property="Visibility" TargetName="Suffix" Value="Collapsed" />
|
||||
</Trigger>
|
||||
<MultiTrigger>
|
||||
<MultiTrigger.Conditions>
|
||||
<Condition Property="helpers:Input.Clearable" Value="True" />
|
||||
<Condition Property="Visibility" SourceName="Placeholder" Value="Collapsed" />
|
||||
</MultiTrigger.Conditions>
|
||||
<Setter Property="Content" TargetName="Suffix">
|
||||
<!--
|
||||
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 TargetType="{x:Type PasswordBox}" x:Key="Ant.PasswordBoxEyeableTemplate">
|
||||
<Grid>
|
||||
<!-- Input Effect -->
|
||||
<Border
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderThickness="{DynamicResource OutlineThickness}"
|
||||
CornerRadius="{TemplateBinding helpers:AntControl.CornerRadius}"
|
||||
Focusable="False"
|
||||
Margin="{Binding BorderThickness, Mode=OneWay, RelativeSource={RelativeSource Self}, Converter={StaticResource ThicknessReverseConverter}}"
|
||||
Opacity="0"
|
||||
x:Name="Effect" />
|
||||
<!-- Input -->
|
||||
<controls:AntBorder
|
||||
Background="{TemplateBinding Background}"
|
||||
BorderBrush="{TemplateBinding BorderBrush}"
|
||||
BorderStyle="{TemplateBinding helpers:AntControl.BorderStyle}"
|
||||
BorderThickness="{TemplateBinding BorderThickness}"
|
||||
CornerRadius="{TemplateBinding helpers:AntControl.CornerRadius}"
|
||||
Padding="{TemplateBinding Padding}"
|
||||
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"
|
||||
UseLayoutRounding="True">
|
||||
<Grid>
|
||||
<Grid.ColumnDefinitions>
|
||||
<!-- Prefix -->
|
||||
<ColumnDefinition Width="Auto" />
|
||||
<!-- Input -->
|
||||
<ColumnDefinition Width="*" />
|
||||
<!-- Eye -->
|
||||
<ColumnDefinition Width="Auto" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<!-- Prefix -->
|
||||
<ContentPresenter
|
||||
Content="{TemplateBinding helpers:Input.Prefix}"
|
||||
Focusable="False"
|
||||
Grid.Column="0"
|
||||
Margin="1,0,5,0"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
x:Name="Prefix" />
|
||||
<!-- Placeholder -->
|
||||
<TextBlock
|
||||
Focusable="False"
|
||||
Foreground="{TemplateBinding helpers:Input.PlaceholderBrush}"
|
||||
Grid.Column="1"
|
||||
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
|
||||
Text="{TemplateBinding helpers:Input.Placeholder}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
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"
|
||||
Margin="{Binding Padding, Mode=OneWay, RelativeSource={RelativeSource TemplatedParent}, Converter={StaticResource ThicknessReverseConverter}}"
|
||||
x:Name="PART_ContentHost" />
|
||||
<!-- Password Text Box -->
|
||||
<TextBox
|
||||
Grid.Column="1"
|
||||
IsTabStop="False"
|
||||
Style="{StaticResource Ant.EditableTextBox}"
|
||||
Text="{Binding Path=(helpers:Input.Password), Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}, UpdateSourceTrigger=PropertyChanged}"
|
||||
Visibility="Collapsed"
|
||||
x:Name="PART_TextBox" />
|
||||
<!-- Eye -->
|
||||
<ToggleButton
|
||||
Focusable="False"
|
||||
Grid.Column="2"
|
||||
IsTabStop="False"
|
||||
Margin="5,0,1,0"
|
||||
Style="{StaticResource Ant.Eyeable}"
|
||||
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
|
||||
Visibility="Collapsed"
|
||||
x:Name="PART_Eye">
|
||||
<!--
|
||||
How to customize Icon?
|
||||
By setting up the locally-defined resource dictionary.
|
||||
-->
|
||||
<controls:Icon Type="eye" />
|
||||
</ToggleButton>
|
||||
</Grid>
|
||||
</controls:AntBorder>
|
||||
</Grid>
|
||||
<ControlTemplate.Triggers>
|
||||
<DataTrigger Binding="{Binding Path=(helpers:Input.Password), Mode=OneWay, RelativeSource={RelativeSource Self}}" Value="">
|
||||
<Setter Property="Visibility" TargetName="Placeholder" Value="Visible" />
|
||||
</DataTrigger>
|
||||
<!-- 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>
|
||||
<Trigger Property="IsFocused" SourceName="PART_TextBox" Value="True">
|
||||
<Setter Property="BorderBrush" Value="{DynamicResource AntDesign.Brush.Primary}" />
|
||||
</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>
|
||||
<Trigger Property="IsKeyboardFocusWithin" Value="True">
|
||||
<Trigger.EnterActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation
|
||||
Duration="0:0:0.3"
|
||||
Storyboard.TargetName="Effect"
|
||||
Storyboard.TargetProperty="Opacity"
|
||||
To="0.2" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</Trigger.EnterActions>
|
||||
<Trigger.ExitActions>
|
||||
<BeginStoryboard>
|
||||
<Storyboard>
|
||||
<DoubleAnimation
|
||||
Duration="0:0:0.3"
|
||||
Storyboard.TargetName="Effect"
|
||||
Storyboard.TargetProperty="Opacity" />
|
||||
</Storyboard>
|
||||
</BeginStoryboard>
|
||||
</Trigger.ExitActions>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
</ControlTemplate>
|
||||
|
||||
<Style
|
||||
BasedOn="{StaticResource Ant.Input}"
|
||||
TargetType="{x:Type PasswordBox}"
|
||||
x:Key="Ant.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>
|
||||
<Style BasedOn="{StaticResource Ant.PasswordBox}" TargetType="PasswordBox" />
|
||||
|
||||
</ResourceDictionary>
|
||||
Reference in New Issue
Block a user