IloveIniesta
IloveIniesta

Reputation: 350

How can i add a hint text in the password in windows phone developing

the style is just like the android textbox.hint(hope i spell it right)
look like a watermark in the middle of the passwordbox
I have learned about that the phonetextbox have a property called hint
but the phonetextbox can't be used as a password input because it can't change my input to chars like stars

Upvotes: 1

Views: 2705

Answers (3)

iupchris10
iupchris10

Reputation: 453

I'm providing a more specific answer with code...

To get the desired effect, you can use a Grid and assign the same Row to both controls. Remember, since the TextBlock sits on top of the TextBox, you will need to account for the user tapping the TextBlock and also TABing into the TextBox.

XAML:

<Grid>
 <PasswordBox x:Name="PasswordTextBox" 
    Grid.Row="0" HorizontalAlignment="Left" 
    GotFocus="PasswordTextBox_GotFocus" LostFocus="PasswordTextBox_LostFocus"

 <TextBlock Name="PasswordWatermark" Text="Password" VerticalAlignment="Center"
    Grid.Row="0" Margin="20,0,0,0" Foreground="Gray" FontSize="24" 
    Tap="PasswordWaterMark_Tap" />
</Grid>

CODE BEHIND:

private void PasswordTextBox_GotFocus(object sender, RoutedEventArgs e)
{
  PasswordWatermark.Visibility = Visibility.Collapsed;
}

private void PasswordWatermark_Tap(object sender, GestureEventArgs e)
{
  PasswordWatermark.Visibility = Visiblity.Collapsed;
  PasswordTextBox.Focus();
}

private void PasswordTextBox_LostFocus(object sender, RoutedEventArgs e)
{
  PasswordWatermark.Visibility = PasswordTextBox.Password.Length > 0 
                                    ? Visibility.Collapsed
                                    : Visibility.Hidden;
}

Upvotes: 4

Hermit Dave
Hermit Dave

Reputation: 3046

how about textblock overlay with reduced opacity ? on tap / click of textbox, hide it

Upvotes: 3

Pedro Lamas
Pedro Lamas

Reputation: 7233

Download the Windows Phone Toolkit and use the PhoneTextbox control.

Upvotes: 2

Related Questions