C#一次隐藏多个图像 [英] C# hide multiple images at once
问题描述
我在一个函数中一次创建50个奇数(星星)。 将这些星星的可见度设置为一次隐藏的好方法是什么? - 或者只是摧毁星星。
I create 50 odd (stars) at once in a function. What is a good way to set the visibility of these stars to hidden in one go? - or just destroy the stars.
谢谢,我对C#相对较新
Thanks, I'm relatively new to C#
public void showStars() {
for (int i = 0; i < 50; i++)
{
Image aStar = new Image();
aStar.Width = 20;
aStar.Height = 20;
aStar.Visibility = Visibility.Visible;
aStar.HorizontalAlignment = Windows.UI.Xaml.HorizontalAlignment.Left;
aStar.VerticalAlignment = Windows.UI.Xaml.VerticalAlignment.Top;
aStar.Source = new BitmapImage(new Uri("ms-appx:///Assets/star_small.png", UriKind.Absolute));
//注意我剪了随机为了简单起见,这里的东西是
double yLocation =(MainPage.ActualHeight / 2)* xRandD;
double xLocation =(MainPage.ActualWidth)* xRandD;
aStar.Margin =新厚度(xLocation,yLocation,0,0);
MainPageGrid.Children.Add(aStar);
}
}
//Note I cut the random stuff out here for simplicity double yLocation = (MainPage.ActualHeight / 2) * xRandD; double xLocation = (MainPage.ActualWidth) * xRandD; aStar.Margin = new Thickness(xLocation, yLocation, 0, 0); MainPageGrid.Children.Add(aStar); } }
推荐答案
有两种方式。
1。要么改变每颗恒星的可见度,要在for循环中折叠。
1. Either change the visiblity of each star to collapsed in a for loop.
2。或更改包含星星的容器的可见性.i.e MainPageGrid.Visibility = System.Windows.Visibilty.Collapsed;
2. Or Change visibility of container containing stars .i.e MainPageGrid.Visibility=System.Windows.Visibilty.Collapsed;
这篇关于C#一次隐藏多个图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!