你好,
你可以设置控件数组。以Image控件为例。首先在xaml中定义5个image控件,命名为image0~image4, 然后
后台创建数组如:
Image[] imagelist = new Image[5];
然后将控件加入数组中就可以循环对它们进行操作了。 下面的例子是点击按钮时循环将图片宽度设置为10.
<StackPanel>
<Image Name ="image0" Source="D:\image\1.jpg" Height="50"/>
<Image Name ="image1" Source="D:\image\3.jpg" Height="50"/>
<Image Name ="image2" Source="D:\image\2.jpg" Height="50"/>
<Image Name ="image3" Source="D:\image\4.jpg" Height="50"/>
<Image Name ="image4" Source="D:\image\5.jpg" Height="50"/>
<Button Click="Button_Click_1">Click</Button>
</StackPanel>
Image[] imagelist = new Image[5];//创建控件数组
public MainWindow()
{
InitializeComponent();
imagelist[0] = image0;
imagelist[1] = image1;
imagelist[2] = image2;
imagelist[3] = image3;
imagelist[4] = image4;
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
for (int i = 0; i < 5; i++)
{
imagelist[i].Width = 10;
}
}
Lisa Zhu [MSFT]
MSDN Community Support | Feedback to us
Develop and promote your apps in Windows Store
Please remember to mark the replies as answers if they help and unmark them if they provide no help.