是否可以标记PasswordBox.SecurePassword
为ReadOnly
?
考虑这个简单的代码:
XAML:
<StackPanel>
<PasswordBox Name="pBox" MinWidth="100" />
<Button Content="OK" Click="Button_Click" Width="50" />
</StackPanel>
C#:
private void Button_Click(object sender, RoutedEventArgs e)
{
pBox.SecurePassword.MakeReadOnly();
Console.WriteLine(pBox.SecurePassword.IsReadOnly());
}
它将输出False
. 为什么?
编辑:为了确保,我尝试了这个,它按预期输出“True”。
private void Button_Click(object sender, RoutedEventArgs e)
{
SecureString s = new SecureString();
s.MakeReadOnly();
Console.WriteLine(s.IsReadOnly());
}