I would like to add a button dynamically in StackLayout
when "add" button is clicked. I wrote stacklayoutname.children.add(button)
, it does not giving me the thing i am looking for.
In xaml:
<StackLayout x:Name="layout">
<Button Text="add" Clicked="Addbutton"/>
</StackLayout>
In code:
private void Addbutton(object sender, EventArgs e)
{
var layout = new StackLayout();
var btn = new Button { Text = "New button", FontSize = 30, TranslationY = 30 };
this.Content = layout;
layout.Children.Add(btn);
}
It is giving only new button and add button is disappearing, but I want whenever we click on add button it should give number of new button equal to the number of clicks on add button.
StackLayout
. And when you say should give number of new button equal to the number of clicks on add button, do you mean you want to add buttons as per each click or just display number of clicks onButton
'sText
? – Curiousity