admin管理员组文章数量:1391850
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.
本文标签: cWPF Image Not Displaying Correctly in Password Visibility ToggleStack Overflow
版权声明:本文标题:c# - WPF Image Not Displaying Correctly in Password Visibility Toggle - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744769457a2624247.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论