我有一个关于在 WPF 中循环变量名的具体问题。
XAML 代码如下所示:
<Grid>
<Button name="button1" Visibility="Collapsed" />
<Button name="button2" Visibility="Collapsed" />
<Button name="button3" Visibility="Collapsed" />
<Button name="button4" Visibility="Collapsed" />
</Grid>
我想知道是否可以使用带有以下数字的 for 循环来遍历变量名称:
private DateTime time = DateTime.Now;
private CultureInfo ci = new CultureInfo("en-GB");
for(int i = 0; i <= 4; i++)
{
/* (*Plus i*): A example as what I want/like to do */
string Year = String.Format(ci, "{0:yyyy}", Time.addDays(i-1));
button(*Plus i*).Visibility = Visibility.Visible;
button(*Plus i*).Name = Year;
}
甚至可以添加一个数字来达到某个变量吗?请帮帮我,谢谢你的任何回应..