سؤال

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

هل كانت مفيدة؟

المحلول 2

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

نصائح أخرى

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;
}

Download the Windows Phone Toolkit and use the PhoneTextbox control.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top