I m still in the beginning stage of learning c#, so i have a question about a part of my code. I strongly have the feeling there should be a way smarter way to accomplish what i try to do:
So what do i have: A WPF window, with a whole bunch of images on it. At the start, i want them all to be set to Hidden, so at the initialize part of the window, i set them all hidden and do it like this:
.....
IMx01y01W.Visibility = Visibility.Hidden;
IMx23y73W.Visibility = Visibility.Hidden;
IMx31y21W.Visibility = Visibility.Hidden;
IMx03y16W.Visibility = Visibility.Hidden;
.....
诸如IMx#y#y#W等图像的名称是合乎逻辑的,其中第2号是变数。
如上所述,我强烈认为,这样做确实应该有某种细致的方法。
=======
EDIT 页: 1
至今为止。
foreach (object obj in LogicalTreeHelper.GetChildren(this))
{
if (obj is Image)
{
Image obj = (Image)item;
obj.Visibility = Visibility.Hidden;
}
//do something
}
The part in the if statement is totally wrong, but i don t know how to go on on this point. can anyone push me a bit more in the right direction ? thanx!