如何验证Windows Phone上是否显示对象?

时间:2013-01-14 11:57:48

标签: c# visibility windows-phone

我需要验证一个对象是否可见,我试着编写这段代码,但它不起作用(NullReferenceException):

if (PasswordConfirm.Visibility != Visibility.Collapsed)
                {
                    labelInsertPassword.Visibility = Visibility.Collapsed;
                    PasswordConfirm.Visibility = Visibility.Collapsed;
                }

我该怎么做? 谢谢!

1 个答案:

答案 0 :(得分:3)

以下snippt在我的情况下运行正常。您需要显示其他与此相关的代码以获得良好的解决方案..

  if (passwordBox1.Visibility == Visibility.Visible)
        MessageBox.Show("Visible");
    else
        MessageBox.Show("Not visible");