如何在Windows Phone中显示带有提示文本的密码框?
我尝试了PasswordBox
和Toolkit's PhoneTextBox
,但需要进行特殊处理以将两者结合起来吗?
如何在Windows Phone中显示带有提示文本的密码框?
我尝试了PasswordBox
和Toolkit's PhoneTextBox
,但需要进行特殊处理以将两者结合起来吗?
在 Windows Phone 8 中使用 Windows Phone Toolkit
在 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();
}
编程愉快!
您可以创建自己的WatermarkedPasswordBox,它将从PasswordBox中提供。这并不困难。这个链接会帮助您: