如何在 Windows Phone 中显示带有提示文本的密码框?
我已经尝试过PasswordBox
and Toolkit's PhoneTextBox
。将两者结合起来有什么特别的吗?
如何在 Windows Phone 中显示带有提示文本的密码框?
我已经尝试过PasswordBox
and Toolkit's PhoneTextBox
。将两者结合起来有什么特别的吗?
为此,我现在使用http://damianblog.com/2011/01/21/wp7-password-watermark/。希望能有更好的方法。
另一种选择:WindowsPhoneControls
此外,Telerik WP 控件的下一个版本有一个 RadPasswordTextBox。
在使用Windows Phone 工具包的 Windows Phone 8 中
恩 Xaml
<Grid Grid.Row="1" Margin="12,0,0,0" x:Name="ContentPanel">
<toolkit:PhoneTextBox Height="72" Margin="0,0,0,270" TextWrapping="Wrap" VerticalAlignment="Bottom" Hint="{Binding LocalizedResources.LblUser, Source={StaticResource LocalizedStrings}}" x:Name="txtUser" />
<toolkit:PhoneTextBox Height="72" Margin="0,0,0,210" TextWrapping="Wrap" Hint="{Binding LocalizedResources.LblPassword, Source={StaticResource LocalizedStrings}}" x:Name="txtPasswordPlace" VerticalAlignment="Bottom" IsReadOnly="True" />
<PasswordBox Margin="0,72,0,210" VerticalAlignment="Bottom" x:Name="txtPassword" LostFocus="PasswordLostFocus" GotFocus="PasswordGotFocus" Opacity="0"/>
<Button x:Name="btnLogin" Content="{Binding LocalizedResources.LblStartSession, Source={StaticResource LocalizedStrings}}" Click="BtnLogin_Click" VerticalAlignment="Bottom" Margin="0,0,0,150" />
</Grid
C#
public void CheckPasswordWatermark()
{
var passwordEmpty = string.IsNullOrEmpty(txtPassword.Password);
txtPasswordPlace.Opacity = passwordEmpty ? 100 : 0;
txtPassword.Opacity = passwordEmpty ? 0 : 100;
}
private void PasswordGotFocus(object sender, RoutedEventArgs e)
{
txtPasswordPlace.Opacity = 0;
txtPassword.Opacity = 100;
}
private void PasswordLostFocus(object sender, RoutedEventArgs e)
{
CheckPasswordWatermark();
}
快乐编码!
也许,尝试编辑phonetextbox的控件模板。用密码框替换文本框。
你可以得到一个密码框版phonetextbox,哈哈
您可以创建自己的 WatermarkedPasswordBox,它将从 PasswordBox 提供。这并不难。此链接将帮助您: