This commit is contained in:
ShrlAlgo
2025-07-11 09:20:23 +08:00
parent c7b104f44f
commit 4d35cadb56
840 changed files with 102347 additions and 11595 deletions

View File

@@ -1,20 +1,10 @@
<!--
This Source Code Form is subject to the terms of the MIT License.
If a copy of the MIT was not distributed with this file, You can obtain one at https://opensource.org/licenses/MIT.
Copyright (C) Leszek Pomianowski and WPF UI Contributors.
All Rights Reserved.
Based on Microsoft XAML for Win UI
Copyright (c) Microsoft Corporation. All Rights Reserved.
-->
<ResourceDictionary
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:WPFluent.Controls"
xmlns:system="clr-namespace:System;assembly=mscorlib">
xmlns:system="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="/WPFluent;component/Resources/Variables.xaml"/>
<ResourceDictionary Source="/WPFluent;component/Resources/Variables.xaml" />
</ResourceDictionary.MergedDictionaries>
<Thickness x:Key="PasswordBoxBorderThemeThickness">1,1,1,1</Thickness>
<Thickness x:Key="PasswordBoxAccentBorderThemeThickness">0,0,0,1</Thickness>
@@ -29,16 +19,16 @@
<MenuItem Command="ApplicationCommands.Paste" />
</ContextMenu>
<Style x:Key="DefaultPasswordBoxStyle" TargetType="{x:Type PasswordBox}">
<Style TargetType="{x:Type PasswordBox}" x:Key="DefaultPasswordBoxStyle">
<!-- Universal WPF UI focus -->
<Setter Property="FocusVisualStyle" Value="{DynamicResource DefaultControlFocusVisualStyle}" />
<!-- Universal WPF UI focus -->
<!-- Universal WPF UI ContextMenu -->
<Setter Property="ContextMenu" Value="{DynamicResource DefaultPasswordBoxContextMenu}" />
<!-- Universal WPF UI ContextMenu -->
<Setter Property="Foreground" Value="{DynamicResource TextControlForeground}" />
<Setter Property="CaretBrush" Value="{DynamicResource TextControlForeground}" />
<Setter Property="Background" Value="{DynamicResource TextControlBackground}" />
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}" />
<Setter Property="CaretBrush" Value="{DynamicResource TextFillColorPrimaryBrush}" />
<Setter Property="Background" Value="{DynamicResource ControlFillColorDefaultBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource TextControlElevationBorderBrush}" />
<Setter Property="BorderThickness" Value="{StaticResource PasswordBoxBorderThemeThickness}" />
<Setter Property="FontSize" Value="{StaticResource ControlContentThemeFontSize}" />
@@ -57,40 +47,40 @@
<ControlTemplate TargetType="{x:Type PasswordBox}">
<Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
<Border
x:Name="ContentBorder"
MinWidth="{TemplateBinding MinWidth}"
MinHeight="{TemplateBinding MinHeight}"
Padding="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding Border.CornerRadius}">
CornerRadius="{TemplateBinding Border.CornerRadius}"
HorizontalAlignment="Stretch"
MinHeight="{TemplateBinding MinHeight}"
MinWidth="{TemplateBinding MinWidth}"
Padding="0"
VerticalAlignment="Stretch"
x:Name="ContentBorder">
<Grid
Margin="{TemplateBinding Padding}"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
Margin="{TemplateBinding Padding}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<controls:PassiveScrollViewer
x:Name="PART_ContentHost"
Style="{DynamicResource DefaultTextBoxScrollViewerStyle}"
TextElement.Foreground="{TemplateBinding Foreground}" />
TextElement.Foreground="{TemplateBinding Foreground}"
x:Name="PART_ContentHost" />
</Grid>
</Border>
<!-- The Accent Border is a separate element so that changes to the border thickness do not affect the position of the element -->
<Border
x:Name="AccentBorder"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
BorderBrush="{DynamicResource ControlStrokeColorDefaultBrush}"
BorderThickness="{StaticResource PasswordBoxAccentBorderThemeThickness}"
CornerRadius="{TemplateBinding Border.CornerRadius}" />
CornerRadius="{TemplateBinding Border.CornerRadius}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
x:Name="AccentBorder" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="IsFocused" Value="True">
<Setter TargetName="AccentBorder" Property="BorderThickness" Value="0,0,0,2" />
<Setter TargetName="AccentBorder" Property="BorderBrush" Value="{DynamicResource TextControlFocusedBorderBrush}" />
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource TextControlBackgroundFocused}" />
<Setter Property="BorderThickness" TargetName="AccentBorder" Value="0,0,0,2" />
<Setter Property="BorderBrush" TargetName="AccentBorder" Value="{DynamicResource SystemFillColorAttentionBrush}" />
<Setter Property="Background" TargetName="ContentBorder" Value="{DynamicResource ControlFillColorInputActiveBrush}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
@@ -98,16 +88,16 @@
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsFocused" Value="False" />
</MultiTrigger.Conditions>
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource TextControlBackgroundPointerOver}" />
<Setter Property="Background" TargetName="ContentBorder" Value="{DynamicResource ControlFillColorSecondaryBrush}" />
</MultiTrigger>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Cursor" Value="IBeam" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource TextControlBackgroundDisabled}" />
<Setter TargetName="ContentBorder" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushDisabled}" />
<Setter TargetName="AccentBorder" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushDisabled}" />
<Setter Property="Foreground" Value="{DynamicResource TextControlForegroundDisabled}" />
<Setter Property="Background" TargetName="ContentBorder" Value="{DynamicResource ControlFillColorDisabledBrush}" />
<Setter Property="BorderBrush" TargetName="ContentBorder" Value="{DynamicResource ControlStrokeColorDefaultBrush}" />
<Setter Property="BorderBrush" TargetName="AccentBorder" Value="{DynamicResource ControlStrokeColorDefaultBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextFillColorDisabledBrush}" />
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
@@ -115,16 +105,16 @@
</Setter>
</Style>
<Style x:Key="DefaultUiPasswordBoxStyle" TargetType="{x:Type controls:PasswordBox}">
<Style TargetType="{x:Type controls:PasswordBox}" x:Key="DefaultUiPasswordBoxStyle">
<!-- Universal WPF UI focus -->
<Setter Property="FocusVisualStyle" Value="{DynamicResource DefaultControlFocusVisualStyle}" />
<!-- Universal WPF UI focus -->
<!-- Universal WPF UI ContextMenu -->
<Setter Property="ContextMenu" Value="{DynamicResource DefaultPasswordBoxContextMenu}" />
<!-- Universal WPF UI ContextMenu -->
<Setter Property="Foreground" Value="{DynamicResource TextControlForeground}" />
<Setter Property="CaretBrush" Value="{DynamicResource TextControlForeground}" />
<Setter Property="Background" Value="{DynamicResource TextControlBackground}" />
<Setter Property="Foreground" Value="{DynamicResource TextFillColorPrimaryBrush}" />
<Setter Property="CaretBrush" Value="{DynamicResource TextFillColorPrimaryBrush}" />
<Setter Property="Background" Value="{DynamicResource ControlFillColorDefaultBrush}" />
<Setter Property="BorderBrush" Value="{DynamicResource TextControlElevationBorderBrush}" />
<Setter Property="BorderThickness" Value="{StaticResource PasswordBoxBorderThemeThickness}" />
<Setter Property="FontSize" Value="{DynamicResource ControlContentThemeFontSize}" />
@@ -146,16 +136,16 @@
<ControlTemplate TargetType="{x:Type controls:PasswordBox}">
<Grid HorizontalAlignment="{TemplateBinding HorizontalAlignment}" VerticalAlignment="{TemplateBinding VerticalAlignment}">
<Border
x:Name="ContentBorder"
MinWidth="{TemplateBinding MinWidth}"
MinHeight="{TemplateBinding MinHeight}"
Padding="0"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Background="{TemplateBinding Background}"
BorderBrush="{TemplateBinding BorderBrush}"
BorderThickness="{TemplateBinding BorderThickness}"
CornerRadius="{TemplateBinding Border.CornerRadius}">
CornerRadius="{TemplateBinding Border.CornerRadius}"
HorizontalAlignment="Stretch"
MinHeight="{TemplateBinding MinHeight}"
MinWidth="{TemplateBinding MinWidth}"
Padding="0"
VerticalAlignment="Stretch"
x:Name="ContentBorder">
<Grid HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
@@ -166,138 +156,138 @@
</Grid.ColumnDefinitions>
<ContentPresenter
x:Name="ControlIconLeft"
Content="{TemplateBinding Icon}"
Grid.Column="0"
Margin="{StaticResource PasswordBoxLeftIconMargin}"
VerticalAlignment="Top"
Content="{TemplateBinding Icon}"
TextElement.FontSize="16"
TextElement.Foreground="{TemplateBinding Foreground}" />
TextElement.Foreground="{TemplateBinding Foreground}"
VerticalAlignment="Top"
x:Name="ControlIconLeft" />
<Grid Grid.Column="1" Margin="{TemplateBinding Padding}">
<controls:PassiveScrollViewer
x:Name="PART_ContentHost"
Style="{DynamicResource DefaultTextBoxScrollViewerStyle}"
TextElement.Foreground="{TemplateBinding Foreground}" />
TextElement.Foreground="{TemplateBinding Foreground}"
x:Name="PART_ContentHost" />
<TextBlock
x:Name="PlaceholderTextBox"
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Margin="0"
Padding="1,0"
Text="{TemplateBinding PlaceholderText}"
VerticalAlignment="Top"
Foreground="{DynamicResource TextControlPlaceholderForeground}"
Text="{TemplateBinding PlaceholderText}" />
x:Name="PlaceholderTextBox" />
</Grid>
<!-- Buttons and Icons have no padding from the main element to allow absolute positions if height is larger than the text entry zone -->
<!-- 按钮和图标与主元素之间没有填充,以便在高度大于文本输入区时允许绝对定位 -->
<controls:Button
x:Name="ClearButton"
Grid.Column="2"
Width="{StaticResource PasswordBoxButtonHeight}"
Height="{StaticResource PasswordBoxButtonHeight}"
Margin="{StaticResource PasswordBoxButtonMargin}"
Padding="{StaticResource PasswordBoxButtonPadding}"
HorizontalAlignment="Center"
VerticalAlignment="Top"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Appearance="Secondary"
Appearance="Primary"
Background="Transparent"
BorderBrush="Transparent"
Command="{Binding Path=TemplateButtonCommand, RelativeSource={RelativeSource TemplatedParent}}"
CommandParameter="clear"
Cursor="Arrow"
Foreground="{DynamicResource TextControlButtonForeground}"
IsTabStop="False">
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Grid.Column="2"
Height="{StaticResource PasswordBoxButtonHeight}"
HorizontalAlignment="Center"
HorizontalContentAlignment="Center"
IsTabStop="False"
Margin="{StaticResource PasswordBoxButtonMargin}"
Padding="{StaticResource PasswordBoxButtonPadding}"
VerticalAlignment="Top"
VerticalContentAlignment="Center"
Width="{StaticResource PasswordBoxButtonHeight}"
x:Name="ClearButton">
<controls:Button.Icon>
<controls:SymbolIcon FontSize="{StaticResource PasswordBoxButtonIconSize}" Symbol="Dismiss24" />
</controls:Button.Icon>
</controls:Button>
<controls:Button
x:Name="RevealButton"
Grid.Column="3"
Width="{StaticResource PasswordBoxButtonHeight}"
Height="{StaticResource PasswordBoxButtonHeight}"
Margin="{StaticResource PasswordBoxButtonMargin}"
Padding="{StaticResource PasswordBoxButtonPadding}"
HorizontalAlignment="Center"
VerticalAlignment="Top"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Appearance="Secondary"
Appearance="Primary"
Background="Transparent"
BorderBrush="Transparent"
Command="{Binding Path=TemplateButtonCommand, RelativeSource={RelativeSource TemplatedParent}}"
CommandParameter="reveal"
Cursor="Arrow"
Foreground="{DynamicResource TextControlButtonForeground}"
IsTabStop="False">
Foreground="{DynamicResource TextFillColorSecondaryBrush}"
Grid.Column="3"
Height="{StaticResource PasswordBoxButtonHeight}"
HorizontalAlignment="Center"
HorizontalContentAlignment="Center"
IsTabStop="False"
Margin="{StaticResource PasswordBoxButtonMargin}"
Padding="{StaticResource PasswordBoxButtonPadding}"
VerticalAlignment="Top"
VerticalContentAlignment="Center"
Width="{StaticResource PasswordBoxButtonHeight}"
x:Name="RevealButton">
<controls:Button.Icon>
<controls:SymbolIcon FontSize="{StaticResource PasswordBoxButtonIconSize}" Symbol="Eye24" />
</controls:Button.Icon>
</controls:Button>
<ContentPresenter
x:Name="ControlIconRight"
Content="{TemplateBinding Icon}"
Grid.Column="4"
Margin="{StaticResource PasswordBoxRightIconMargin}"
VerticalAlignment="Top"
Content="{TemplateBinding Icon}"
TextElement.FontSize="16"
TextElement.Foreground="{TemplateBinding Foreground}" />
TextElement.Foreground="{TemplateBinding Foreground}"
VerticalAlignment="Top"
x:Name="ControlIconRight" />
</Grid>
</Border>
<!-- The Accent Border is a separate element so that changes to the border thickness do not affect the position of the element -->
<Border
x:Name="AccentBorder"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
BorderBrush="{DynamicResource ControlStrokeColorDefaultBrush}"
BorderThickness="{StaticResource PasswordBoxAccentBorderThemeThickness}"
CornerRadius="{TemplateBinding Border.CornerRadius}" />
CornerRadius="{TemplateBinding Border.CornerRadius}"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
x:Name="AccentBorder" />
</Grid>
<ControlTemplate.Triggers>
<Trigger Property="CurrentPlaceholderEnabled" Value="False">
<Setter TargetName="PlaceholderTextBox" Property="Visibility" Value="Collapsed" />
<Setter Property="Visibility" TargetName="PlaceholderTextBox" Value="Collapsed" />
</Trigger>
<Trigger Property="ShowClearButton" Value="False">
<Setter TargetName="ClearButton" Property="Visibility" Value="Collapsed" />
<Setter TargetName="ClearButton" Property="Margin" Value="0" />
<Setter Property="Visibility" TargetName="ClearButton" Value="Collapsed" />
<Setter Property="Margin" TargetName="ClearButton" Value="0" />
</Trigger>
<Trigger Property="ClearButtonEnabled" Value="False">
<Setter TargetName="ClearButton" Property="Visibility" Value="Collapsed" />
<Setter TargetName="ClearButton" Property="Margin" Value="0" />
<Setter Property="Visibility" TargetName="ClearButton" Value="Collapsed" />
<Setter Property="Margin" TargetName="ClearButton" Value="0" />
</Trigger>
<Trigger Property="RevealButtonEnabled" Value="False">
<Setter TargetName="RevealButton" Property="Visibility" Value="Collapsed" />
<Setter TargetName="RevealButton" Property="Margin" Value="0" />
<Setter Property="Visibility" TargetName="RevealButton" Value="Collapsed" />
<Setter Property="Margin" TargetName="RevealButton" Value="0" />
</Trigger>
<Trigger Property="IsPasswordRevealed" Value="True">
<Setter TargetName="RevealButton" Property="Icon">
<Setter Property="Icon" TargetName="RevealButton">
<Setter.Value>
<controls:SymbolIcon Symbol="EyeOff24" />
</Setter.Value>
</Setter>
</Trigger>
<Trigger Property="IconPlacement" Value="Left">
<Setter TargetName="ControlIconRight" Property="Visibility" Value="Collapsed" />
<Setter TargetName="ControlIconRight" Property="Margin" Value="0" />
<Setter Property="Visibility" TargetName="ControlIconRight" Value="Collapsed" />
<Setter Property="Margin" TargetName="ControlIconRight" Value="0" />
</Trigger>
<Trigger Property="IconPlacement" Value="Right">
<Setter TargetName="ControlIconLeft" Property="Visibility" Value="Collapsed" />
<Setter TargetName="ControlIconLeft" Property="Margin" Value="0" />
<Setter Property="Visibility" TargetName="ControlIconLeft" Value="Collapsed" />
<Setter Property="Margin" TargetName="ControlIconLeft" Value="0" />
</Trigger>
<Trigger Property="Icon" Value="{x:Null}">
<Setter TargetName="ControlIconRight" Property="Visibility" Value="Collapsed" />
<Setter TargetName="ControlIconRight" Property="Margin" Value="0" />
<Setter TargetName="ControlIconLeft" Property="Visibility" Value="Collapsed" />
<Setter TargetName="ControlIconLeft" Property="Margin" Value="0" />
<Setter Property="Visibility" TargetName="ControlIconRight" Value="Collapsed" />
<Setter Property="Margin" TargetName="ControlIconRight" Value="0" />
<Setter Property="Visibility" TargetName="ControlIconLeft" Value="Collapsed" />
<Setter Property="Margin" TargetName="ControlIconLeft" Value="0" />
</Trigger>
<Trigger Property="IsFocused" Value="True">
<Setter TargetName="AccentBorder" Property="BorderThickness" Value="0,0,0,2" />
<Setter TargetName="AccentBorder" Property="BorderBrush" Value="{DynamicResource TextControlFocusedBorderBrush}" />
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource TextControlBackgroundFocused}" />
<Setter Property="BorderThickness" TargetName="AccentBorder" Value="0,0,0,2" />
<Setter Property="BorderBrush" TargetName="AccentBorder" Value="{DynamicResource SystemFillColorAttentionBrush}" />
<Setter Property="Background" TargetName="ContentBorder" Value="{DynamicResource ControlFillColorInputActiveBrush}" />
</Trigger>
<MultiTrigger>
<MultiTrigger.Conditions>
@@ -305,19 +295,19 @@
<Condition Property="IsMouseOver" Value="True" />
<Condition Property="IsFocused" Value="False" />
</MultiTrigger.Conditions>
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource TextControlBackgroundPointerOver}" />
<Setter Property="Background" TargetName="ContentBorder" Value="{DynamicResource ControlFillColorSecondaryBrush}" />
</MultiTrigger>
<Trigger Property="IsEnabled" Value="True">
<Setter Property="Cursor" Value="IBeam" />
</Trigger>
<Trigger Property="IsEnabled" Value="False">
<Setter TargetName="ContentBorder" Property="Background" Value="{DynamicResource TextControlBackgroundDisabled}" />
<Setter TargetName="ContentBorder" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushDisabled}" />
<Setter TargetName="AccentBorder" Property="BorderBrush" Value="{DynamicResource TextControlBorderBrushDisabled}" />
<Setter TargetName="ControlIconLeft" Property="TextElement.Foreground" Value="{DynamicResource TextControlForegroundDisabled}" />
<Setter TargetName="ControlIconRight" Property="TextElement.Foreground" Value="{DynamicResource TextControlForegroundDisabled}" />
<Setter TargetName="PlaceholderTextBox" Property="Foreground" Value="{DynamicResource TextControlForegroundDisabled}" />
<Setter Property="Foreground" Value="{DynamicResource TextControlForegroundDisabled}" />
<Setter Property="Background" TargetName="ContentBorder" Value="{DynamicResource ControlFillColorDisabledBrush}" />
<Setter Property="BorderBrush" TargetName="ContentBorder" Value="{DynamicResource ControlStrokeColorDefaultBrush}" />
<Setter Property="BorderBrush" TargetName="AccentBorder" Value="{DynamicResource ControlStrokeColorDefaultBrush}" />
<Setter Property="TextElement.Foreground" TargetName="ControlIconLeft" Value="{DynamicResource TextFillColorDisabledBrush}" />
<Setter Property="TextElement.Foreground" TargetName="ControlIconRight" Value="{DynamicResource TextFillColorDisabledBrush}" />
<Setter Property="Foreground" TargetName="PlaceholderTextBox" Value="{DynamicResource TextFillColorDisabledBrush}" />
<Setter Property="Foreground" Value="{DynamicResource TextFillColorDisabledBrush}" />
<Setter Property="ClearButtonEnabled" Value="False" />
<Setter Property="RevealButtonEnabled" Value="False" />
</Trigger>

View File

@@ -1,68 +1,59 @@
using System.Diagnostics;
// ReSharper disable once CheckNamespace
using System.Diagnostics;
namespace WPFluent.Controls;
#pragma warning disable SA1601
public partial class PasswordBox
{
private class PasswordHelper
{
private string _currentPassword;
private string _currentText;
private string _newPasswordValue;
private readonly PasswordBox _passwordBox;
private string currentPassword;
private string currentText;
private string newPasswordValue;
private readonly PasswordBox passwordBox;
public PasswordHelper(PasswordBox passwordBox)
{
_passwordBox = passwordBox;
_currentText = string.Empty;
_newPasswordValue = string.Empty;
_currentPassword = string.Empty;
this.passwordBox = passwordBox;
currentText = string.Empty;
newPasswordValue = string.Empty;
currentPassword = string.Empty;
}
private bool IsDeleteOption()
{
Debug.Assert(_currentText == _passwordBox.Text, "_currentText == _passwordBox.Text");
Debug.Assert(_currentPassword == _passwordBox.Password, "_currentPassword == _passwordBox.Password");
Debug.Assert(currentText == passwordBox.Text, "_currentText == _passwordBox.Text");
Debug.Assert(currentPassword == passwordBox.Password, "_currentPassword == _passwordBox.Password");
return _currentText.Length < _currentPassword.Length;
return currentText.Length < currentPassword.Length;
}
private void UpdatePasswordWithInputCharacter(int insertIndex, string insertValue)
{
Debug.Assert(_currentText == _passwordBox.Text, "_currentText == _passwordBox.Text");
Debug.Assert(currentText == passwordBox.Text, "_currentText == _passwordBox.Text");
if(_currentText.Length == _newPasswordValue.Length)
if(currentText.Length == newPasswordValue.Length)
{
// If it's a direct character replacement, remove the existing one before inserting the new one.
_newPasswordValue = _newPasswordValue.Remove(insertIndex, 1).Insert(insertIndex, insertValue);
newPasswordValue = newPasswordValue.Remove(insertIndex, 1).Insert(insertIndex, insertValue);
}
else
{
_newPasswordValue = _newPasswordValue.Insert(insertIndex, insertValue);
newPasswordValue = newPasswordValue.Insert(insertIndex, insertValue);
}
}
public string GetNewPassword()
{
_currentPassword = GetPassword();
_newPasswordValue = _currentPassword;
_currentText = _passwordBox.Text;
var selectionIndex = _passwordBox.SelectionStart;
var passwordChar = _passwordBox.PasswordChar;
var newCharacters = _currentText.Replace(passwordChar.ToString(), string.Empty);
currentPassword = GetPassword();
newPasswordValue = currentPassword;
currentText = passwordBox.Text;
var selectionIndex = passwordBox.SelectionStart;
var passwordChar = passwordBox.PasswordChar;
var newCharacters = currentText.Replace(passwordChar.ToString(), string.Empty);
bool isDeleted = false;
if(IsDeleteOption())
{
_newPasswordValue = _currentPassword.Remove(
selectionIndex,
_currentPassword.Length - _currentText.Length);
newPasswordValue = currentPassword.Remove(selectionIndex, currentPassword.Length - currentText.Length);
isDeleted = true;
}
@@ -70,25 +61,25 @@ public partial class PasswordBox
{
case > 1:
{
var index = _currentText.IndexOf(newCharacters[0]);
var index = currentText.IndexOf(newCharacters[0]);
_newPasswordValue =
index > _newPasswordValue.Length - 1
? $"{_newPasswordValue}{newCharacters}"
: _newPasswordValue.Insert(index, newCharacters);
newPasswordValue =
index > newPasswordValue.Length - 1
? $"{newPasswordValue}{newCharacters}"
: newPasswordValue.Insert(index, newCharacters);
break;
}
case 1:
{
for(int i = 0; i < _currentText.Length; i++)
for(int i = 0; i < currentText.Length; i++)
{
if(_currentText[i] == passwordChar)
if(currentText[i] == passwordChar)
{
continue;
}
UpdatePasswordWithInputCharacter(i, _currentText[i].ToString());
UpdatePasswordWithInputCharacter(i, currentText[i].ToString());
break;
}
@@ -104,9 +95,9 @@ public partial class PasswordBox
}
}
return _newPasswordValue;
return newPasswordValue;
}
public string GetPassword() => _passwordBox.Password ?? string.Empty;
public string GetPassword() => passwordBox.Password ?? string.Empty;
}
}