有什么解决方案可以简化此代码吗?我只想在几个相同类型的对象中设置相同的属性。这些对象是 Windows 8 应用程序中的文本框。我认为这可能与 Array 和 foreach 相关...但不确定谢谢
private void makeVisible(int x)
{
if (x == 1)
{
field2.Visibility = Visibility.Visible;
field3.Visibility = Visibility.Visible;
field4.Visibility = Visibility.Visible;
field6.Visibility = Visibility.Visible;
field8.Visibility = Visibility.Visible;
field9.Visibility = Visibility.Visible;
field11.Visibility = Visibility.Visible;
}
if (x == 0)
{
field2.Visibility = Visibility.Collapsed;
field3.Visibility = Visibility.Collapsed;
field4.Visibility = Visibility.Collapsed;
field6.Visibility = Visibility.Collapsed;
field8.Visibility = Visibility.Collapsed;
field9.Visibility = Visibility.Collapsed;
field11.Visibility = Visibility.Collapsed;
errorReporter.Visibility = Visibility.Collapsed;
}
}