I have a specific question about looping variable names in WPF.
XAML code looks like:
<Grid>
<Button name="button1" Visibility="Collapsed" />
<Button name="button2" Visibility="Collapsed" />
<Button name="button3" Visibility="Collapsed" />
<Button name="button4" Visibility="Collapsed" />
</Grid>
I wonder if it is possible to loop over the variable names with something as a for loop with a number like:
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;
}
Is it even possible to add a number to reach a certain variable?
please help me out, thank you for any response..
If you want to iterate over buttons in that Grid, than your can assign name to the Grid, say buttonsGrid. Than you can iterate over it’s Children property