试图在图片点击时隐藏密码
Trying to hide password on image click
试图在点击图片时隐藏密码,提供了代码 below.In xaml 部分我在后面的代码中使用了文本框来接受密码 我已经编写了隐藏代码但是它在使可见性为假的同时给出错误。
参考图片
<TextBox Name="txtBoxPassw" Height="45" Width="246" InputScope="Password" Margin="10,5,5,5" Background="White" VerticalAlignment="Center"
FontSize="25" FontFamily="Segoe UI Light" Visibility="Visible" Foreground="Black" Padding="50,5,5,5" TextWrapping="Wrap"
BorderThickness="0,0,0,2" BorderBrush="Gray" />
<Canvas Margin="58,-45,136,0">
<Image x:Name="passLogo" Source="Assets/ic_pass.png" Height="41" Width="41" />
</Canvas>
<!--19oct-->
<TextBlock Name="txtBlockPasswFieldError" Grid.Row="2" Margin="-60,0,0,0" Foreground="Black" Text="*Please enter valid name"
HorizontalAlignment="Center" Visibility="Visible" FontSize="11"/>
<!--19oct-->
<Image Name="showimg" Source="Assets/show_pass.png" Width="25" Height="50" Margin="50,15,40,10" Tapped="Image_Tapped" Stretch="Uniform"/>
<TextBlock Name="showPass"
Text="Show Password"
Foreground="#303030"
FontSize="15"
FontFamily="Koblenz Serial Medium"
Margin="200,-45,15,20" />
cs文件
private void Image_Tapped(object sender, TappedRoutedEventArgs e)
{
BitmapImage bitcurrentimage = showimg.Source as BitmapImage;
//if (showimg.Source == new BitmapImage(new Uri("ms-appx:///Assets/show_pass.png", UriKind.RelativeOrAbsolute)))
if (bitcurrentimage.UriSource.AbsoluteUri == "ms-appx:///Assets/show_pass.png")
{
//passBox.PasswordRevealMode = PasswordRevealMode.Visible;
txtBoxPassw.Visibility = Visibility.Visible;
showPass.Text = "Hide Password";
SetImage("ms-appx:///Assets/hide_pass_.png");
}
else
{
//passBox.PasswordRevealMode = PasswordRevealMode.Hidden;
txtBoxPassw.Visibility = Visibility.Visible.Equals(false);
showPass.Text = "Show Password";
SetImage("ms-appx:///Assets/show_pass.png");
}
}
在Winform中有一个文本框参数'PasswordChar',如果你将它设置为一个字符(例如*),它将把文本框中的所有字符替换为该字符。如果将 passwordChar 设置为 '\o' (PasswordBox.PasswordChar = '\0';),它将像正常情况一样显示所有字符。我希望 UWP 中有类似的东西 - 我不喜欢 UWP。
actually i want to put validation(if (Utility.isEmptyString(txtBoxPassw.Text)) on the string typed in passwordbox, but when i am trying it is giving error "'PasswordBox' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'PasswordBox' could be found (are you missing a using directive or an assembly reference?)"
这是您的最后一条评论,根据这条评论,我假设您接受使用内置控件的方法 PasswordBox
而不是创建您自己的控件。
那你可以参考PasswordBox class, unlike a TextBox
or a TextBlock
, PasswordBox
does not have a property named "Text". I think what you need is the PasswordBox.Password property.
例如:
<PasswordBox x:Name="passwb" Height="30" IsPasswordRevealButtonEnabled="True" />
<Button Content="click" VerticalAlignment="Bottom" Click="Button_Click" />
后面的代码:
private void Button_Click(object sender, RoutedEventArgs e)
{
var pass = passwb.Password;
}
这里的pass
表示"passwb".
的PasswordBox
当前持有的密码
试图在点击图片时隐藏密码,提供了代码 below.In xaml 部分我在后面的代码中使用了文本框来接受密码 我已经编写了隐藏代码但是它在使可见性为假的同时给出错误。
参考图片
<TextBox Name="txtBoxPassw" Height="45" Width="246" InputScope="Password" Margin="10,5,5,5" Background="White" VerticalAlignment="Center"
FontSize="25" FontFamily="Segoe UI Light" Visibility="Visible" Foreground="Black" Padding="50,5,5,5" TextWrapping="Wrap"
BorderThickness="0,0,0,2" BorderBrush="Gray" />
<Canvas Margin="58,-45,136,0">
<Image x:Name="passLogo" Source="Assets/ic_pass.png" Height="41" Width="41" />
</Canvas>
<!--19oct-->
<TextBlock Name="txtBlockPasswFieldError" Grid.Row="2" Margin="-60,0,0,0" Foreground="Black" Text="*Please enter valid name"
HorizontalAlignment="Center" Visibility="Visible" FontSize="11"/>
<!--19oct-->
<Image Name="showimg" Source="Assets/show_pass.png" Width="25" Height="50" Margin="50,15,40,10" Tapped="Image_Tapped" Stretch="Uniform"/>
<TextBlock Name="showPass"
Text="Show Password"
Foreground="#303030"
FontSize="15"
FontFamily="Koblenz Serial Medium"
Margin="200,-45,15,20" />
cs文件
private void Image_Tapped(object sender, TappedRoutedEventArgs e)
{
BitmapImage bitcurrentimage = showimg.Source as BitmapImage;
//if (showimg.Source == new BitmapImage(new Uri("ms-appx:///Assets/show_pass.png", UriKind.RelativeOrAbsolute)))
if (bitcurrentimage.UriSource.AbsoluteUri == "ms-appx:///Assets/show_pass.png")
{
//passBox.PasswordRevealMode = PasswordRevealMode.Visible;
txtBoxPassw.Visibility = Visibility.Visible;
showPass.Text = "Hide Password";
SetImage("ms-appx:///Assets/hide_pass_.png");
}
else
{
//passBox.PasswordRevealMode = PasswordRevealMode.Hidden;
txtBoxPassw.Visibility = Visibility.Visible.Equals(false);
showPass.Text = "Show Password";
SetImage("ms-appx:///Assets/show_pass.png");
}
}
在Winform中有一个文本框参数'PasswordChar',如果你将它设置为一个字符(例如*),它将把文本框中的所有字符替换为该字符。如果将 passwordChar 设置为 '\o' (PasswordBox.PasswordChar = '\0';),它将像正常情况一样显示所有字符。我希望 UWP 中有类似的东西 - 我不喜欢 UWP。
actually i want to put validation(if (Utility.isEmptyString(txtBoxPassw.Text)) on the string typed in passwordbox, but when i am trying it is giving error "'PasswordBox' does not contain a definition for 'Text' and no extension method 'Text' accepting a first argument of type 'PasswordBox' could be found (are you missing a using directive or an assembly reference?)"
这是您的最后一条评论,根据这条评论,我假设您接受使用内置控件的方法 PasswordBox
而不是创建您自己的控件。
那你可以参考PasswordBox class, unlike a TextBox
or a TextBlock
, PasswordBox
does not have a property named "Text". I think what you need is the PasswordBox.Password property.
例如:
<PasswordBox x:Name="passwb" Height="30" IsPasswordRevealButtonEnabled="True" />
<Button Content="click" VerticalAlignment="Bottom" Click="Button_Click" />
后面的代码:
private void Button_Click(object sender, RoutedEventArgs e)
{
var pass = passwb.Password;
}
这里的pass
表示"passwb".
PasswordBox
当前持有的密码