watermarked PasswordBox in winrt

耗尽温柔 提交于 2019-12-06 07:09:26

Take a look on WinRT XAML Toolkit.

They also have

  1. WatermarkTextBox
  2. WatermarkPasswordBox

By yourself you can implement your own controls:

in .xaml:

 <Border x:Name="brdPassword" Margin="5,0,5,10" BorderThickness="2" BorderBrush="White" CornerRadius="5" Grid.Row="0"
                                Background="White" Height="50" VerticalAlignment="Stretch">
                           <Grid>
                <TextBox x:Name="PasswordWatermark" TextWrapping="Wrap" 
                          Text="Watermark"  Foreground="#FFC4C4C4" IsHitTestVisible="False" 
                          Background="{x:Null}" BorderThickness="0" Padding="0,-10" 
                          FontSize="26.667" />
                 <PasswordBox x:Name="pbPassword" LostFocus="PasswordLostFocus"
                         GotFocus="PasswordGotFocus" Background="{x:Null}" 
                         FontSize="26.667" Margin="0,-12,0,-9" VerticalAlignment="Center"
                         BorderThickness="0" Opacity="0" />
                </Grid>
                </Border>

in .cs

    private void PasswordLostFocus(object sender, RoutedEventArgs e)
    {
        CheckPasswordWatermark();
    }

    private void CheckPasswordWatermark()
    {
        var passwordEmpty = string.IsNullOrEmpty(pbPassword.Password);
        PasswordWatermark.Opacity = passwordEmpty ? 100 : 0;
        pbPassword.Opacity = passwordEmpty ? 0 : 100;
    }

    private void PasswordGotFocus(object sender, RoutedEventArgs e)
    {
        PasswordWatermark.Opacity = 0;
        pbPassword.Opacity = 100;
    }

Hope it's help

I don't think we can put watermark in the Password control. You can put a TextBox with wartermark in the same row and same column with the Password control, then handle the two controls' GotFocus and LostFocus events to make the control Visible or Collapsed.

There is no toolkit yet which provides watermarked password box. However this may help:-

http://code.msdn.microsoft.com/windowsdesktop/Watermarked-TextBox-and-444ebdec

Also, check out http://julmar.com/blog/mark/?p=300 for both a Textbox and PasswordBox implementation for WinRT.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!