fixed #422
This commit is contained in:
1 parent
8b48ce958d
commit
79694355de
2 files changed
+44
-3
No files matched your search
@@ -7,7 +7,8 @@
|
|||||||
Background="{DynamicResource RegionBrush}">
|
Background="{DynamicResource RegionBrush}">
|
||||||
<hc:TransitioningContentControl>
|
<hc:TransitioningContentControl>
|
||||||
<StackPanel Margin="32">
|
<StackPanel Margin="32">
|
||||||
<hc:PasswordBox ShowClearButton="True" Password="123456"/>
|
<hc:PasswordBox Name="PasswordBoxDemo" ShowClearButton="True" Password="123456" IsSafeEnabled="False"/>
|
||||||
|
<TextBox Text="{Binding UnsafePassword,ElementName=PasswordBoxDemo,UpdateSourceTrigger=PropertyChanged}" Margin="0,6,0,0"/>
|
||||||
<hc:PasswordBox Password="123456" Margin="0,16,0,0"/>
|
<hc:PasswordBox Password="123456" Margin="0,16,0,0"/>
|
||||||
|
|
||||||
<hc:PasswordBox ShowClearButton="True" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr1}}" Password="123456" Margin="0,32,0,0"/>
|
<hc:PasswordBox ShowClearButton="True" hc:InfoElement.Title="{ex:Lang Key={x:Static langs:LangKeys.TitleDemoStr1}}" Password="123456" Margin="0,32,0,0"/>
|
||||||
|
|||||||
@@ -26,7 +26,6 @@ namespace HandyControl.Controls
|
|||||||
|
|
||||||
private System.Windows.Controls.TextBox _textBox;
|
private System.Windows.Controls.TextBox _textBox;
|
||||||
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// 掩码字符
|
/// 掩码字符
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -107,6 +106,40 @@ namespace HandyControl.Controls
|
|||||||
set => SetValue(ShowPasswordProperty, ValueBoxes.BooleanBox(value));
|
set => SetValue(ShowPasswordProperty, ValueBoxes.BooleanBox(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static readonly DependencyProperty IsSafeEnabledProperty = DependencyProperty.Register(
|
||||||
|
"IsSafeEnabled", typeof(bool), typeof(PasswordBox), new PropertyMetadata(ValueBoxes.TrueBox, OnIsSafeEnabledChanged));
|
||||||
|
|
||||||
|
private static void OnIsSafeEnabledChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
var p = (PasswordBox)d;
|
||||||
|
p.SetCurrentValue(UnsafePasswordProperty, !(bool)e.NewValue ? p.Password : string.Empty);
|
||||||
|
}
|
||||||
|
|
||||||
|
public bool IsSafeEnabled
|
||||||
|
{
|
||||||
|
get => (bool) GetValue(IsSafeEnabledProperty);
|
||||||
|
set => SetValue(IsSafeEnabledProperty, ValueBoxes.BooleanBox(value));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static readonly DependencyProperty UnsafePasswordProperty = DependencyProperty.Register(
|
||||||
|
"UnsafePassword", typeof(string), typeof(PasswordBox), new FrameworkPropertyMetadata(default(string),
|
||||||
|
FrameworkPropertyMetadataOptions.BindsTwoWayByDefault, OnUnsafePasswordChanged));
|
||||||
|
|
||||||
|
private static void OnUnsafePasswordChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||||
|
{
|
||||||
|
var p = (PasswordBox) d;
|
||||||
|
if (!p.IsSafeEnabled)
|
||||||
|
{
|
||||||
|
p.Password = e.NewValue != null ? e.NewValue.ToString() : string.Empty;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public string UnsafePassword
|
||||||
|
{
|
||||||
|
get => (string) GetValue(UnsafePasswordProperty);
|
||||||
|
set => SetValue(UnsafePasswordProperty, value);
|
||||||
|
}
|
||||||
|
|
||||||
public static readonly DependencyProperty MaxLengthProperty =
|
public static readonly DependencyProperty MaxLengthProperty =
|
||||||
System.Windows.Controls.TextBox.MaxLengthProperty.AddOwner(typeof(PasswordBox));
|
System.Windows.Controls.TextBox.MaxLengthProperty.AddOwner(typeof(PasswordBox));
|
||||||
|
|
||||||
@@ -193,6 +226,7 @@ namespace HandyControl.Controls
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Equals(ActualPasswordBox.Password, value)) return;
|
||||||
ActualPasswordBox.Password = value;
|
ActualPasswordBox.Password = value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -317,7 +351,13 @@ namespace HandyControl.Controls
|
|||||||
_textBox.Clear();
|
_textBox.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e) => VerifyData();
|
private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
|
||||||
|
{
|
||||||
|
if (VerifyData() && !IsSafeEnabled)
|
||||||
|
{
|
||||||
|
SetCurrentValue(UnsafePasswordProperty, ActualPasswordBox.Password);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void TextBox_TextChanged(object sender, TextChangedEventArgs e) => VerifyData();
|
private void TextBox_TextChanged(object sender, TextChangedEventArgs e) => VerifyData();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in new issue
Block a user