Hello everyone.
i writing some codes and need to make some Buttons in Code-Behind.
for loop would do that, but i can not set any Name or ID for Buttons,
and because of that, i cant define any property for each of Buttons separately.
this is my code:
for (int i=1 ;i<=10; i++)
{
Button but_Icon = new Button
{
HeightRequest = 80,
Text = "",
VerticalOptions = LayoutOptions.Start,
HorizontalOptions = LayoutOptions.Center
Name = "but_Icon" + i.toString(); //this works on C# but not works here!
}
Label lab_Icon = new Label
{
Text = "Application NO." + i.ToString(),
VerticalOptions = LayoutOptions.Start,
Font = Font.SystemFontOfSize(NamedSize.Medium,FontAttributes.Italic),
HorizontalOptions = LayoutOptions.Center
};
if (i % 2 == 0)
{
grid.Children.Add(but_Icon, 1, i - 2);
grid.Children.Add(lab_Icon, 1, i - 1);
}
else
{
grid.Children.Add(but_Icon, 0, i - 1);
grid.Children.Add(lab_Icon, 0, i);
}
}
i know can use x:Name in XAML, but not works for something like this code.
any suggestion i appreciate.