我需要验证一个对象是否可见,我试着编写这段代码,但它不起作用(NullReferenceException):
if (PasswordConfirm.Visibility != Visibility.Collapsed)
{
labelInsertPassword.Visibility = Visibility.Collapsed;
PasswordConfirm.Visibility = Visibility.Collapsed;
}
我该怎么做? 谢谢!
答案 0 :(得分:3)
以下snippt在我的情况下运行正常。您需要显示其他与此相关的代码以获得良好的解决方案..
if (passwordBox1.Visibility == Visibility.Visible)
MessageBox.Show("Visible");
else
MessageBox.Show("Not visible");