I'm developing a WPF application and I'm encountering an issue with an image that is supposed to toggle the visibility of a password field. The image for hiding the password (VisibilityOff.png
) is not displaying correctly; instead, it shows as a white space. However, the button is still functional, as clicking on the white space correctly hides the password and shows the image for revealing the password (Visibility.png
).
Here’s a snippet of the relevant XAML code:
<Image x:Name="PasswordEyeIcon"
Source="pack://application:,,,/img/Visibility.png"
Width="20" Height="20" Margin="0,0,10,0"
VerticalAlignment="Center" HorizontalAlignment="Right"
Cursor="Hand" MouseDown="PasswordEyeIcon_MouseDown"/>
And here’s the code behind for toggling the visibility:
private void PasswordEyeIcon_MouseDown(object sender, MouseButtonEventArgs e)
{
if (isPasswordVisible)
{
// Hide the TextBox and show the PasswordBox
PasswordTextBox.Visibility = Visibility.Collapsed;
PasswordBox.Visibility = Visibility.Visible;
PasswordBox.Password = PasswordTextBox.Text;
PasswordEyeIcon.Source = new BitmapImage(new Uri("pack://application:,,,/img/Visibility.png"));
isPasswordVisible = false;
}
else
{
// Show the TextBox and hide the PasswordBox
PasswordTextBox.Text = PasswordBox.Password;
PasswordBox.Visibility = Visibility.Collapsed;
PasswordTextBox.Visibility = Visibility.Visible;
PasswordEyeIcon.Source = new BitmapImage(new Uri("pack://application:,,,/img/VisibilityOff.png"));
isPasswordVisible = true;
}
}
What I've Tried:
1. Verified that the image file VisibilityOff.png is included in the project and set to Resource.
What I'm Expecting:
I expect that when I click the visibility toggle button (the eye icon), the `VisibilityOff.png` image should display correctly, indicating that the password is currently visible. When the password is hidden, the `Visibility.png` image should be displayed instead. The toggle functionality should work seamlessly, allowing users to switch between viewing and hiding the password without any visual issues.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744769458a4592667.html
评论列表(0条)