我正在公司内部开发一个应用程序,他们需要某种用户身份验证。我拥有的代码非常适合身份验证,但存在一些视觉错误。
我知道我的代码保留Password
在内存中,不是应该这样做,但由于这是公司内部的,因此破解它没有任何好处。我想听听是否有人有更好的解决方案。这可能是不可能的,因为PasswordBox
in 在UserControl
inside a中使用UserControl
。这必须一直向上发送数据,我不知道如何安全地做到这一点。
现在,回到主题。WatermarkTextBox
我不久前使用下面显示的代码创建了。下面的代码可以正常工作。
<TextBlock Text="{Binding Path=Watermark, RelativeSource={RelativeSource AncestorType=UserControl},
FallbackValue='This prompt dissappears as you type...'}"
Visibility="{Binding ElementName=txtUserEntry, Path=Text.IsEmpty,
Converter={StaticResource BooleanToVisibilityConverter}}" />
<TextBox Name="txtUserEntry"
Text="{Binding Path=Text, UpdateSourceTrigger=PropertyChanged,
RelativeSource={RelativeSource AncestorType=UserControl}}" />
现在我为我的PasswordWatermarkBox
.
<TextBlock Text="{Binding Path=Watermark, RelativeSource={RelativeSource AncestorType=UserControl},
FallbackValue='This prompt dissappears as you type...'}"
Visibility="{Binding ElementName=txtUserEntry, Path=Password.IsEmpty,
Converter={StaticResource BooleanToVisibilityConverter}}" />
<PasswordBox Name="txtUserEntry"
local:PasswordHelper.Attach="True"
local:PasswordHelper.Password="{Binding Path=Text,
UpdateSourceTrigger=PropertyChanged,
RelativeSource={RelativeSource AncestorType=UserControl},
Mode=TwoWay}" />
在这里,我可以使用Text
DP 从附加属性中获取纯文本密码local:PasswordHelper.Password
。这里的问题是Watermark
不更新。检查Text.IsEmpty
第一个示例有效,但此处无效。也Password.IsEmpty
不起作用,local:PasswordHelper.Password.IsEmpty
也不起作用。