I'm creating a Xamarin.Forms app using c#.
There is a Button in a Page and i want to add a new Label in StackLayout that is in the Main Page
when the Button is clicked.
I tried to set the FieldModifier
property of the StackLayout
public in the XAML file, but it didn't work...
This is the layout code (i want to add the label into MainStackLayout
) and the cs method of the Button click:
<ContentPage.Content>
<ScrollView>
<StackLayout BackgroundColor="white">
<StackLayout Orientation="Horizontal" x:Name="MainStackLayout" x:FieldModifier="public" >
</StackLayout>
<Button
Text="Add Counter"
BackgroundColor="darkgreen"
HorizontalOptions="FillAndExpand"
CornerRadius="0"
HeightRequest="80"
TextColor="white"
FontAttributes="Bold"
x:Name="AddCounter_btn"
Clicked="AddCounter_btn_Clicked"
>
</Button>
</StackLayout>
</ScrollView>
</ContentPage.Content>
private void StartCount_btn_Clicked(object sender,EventArgs e)
{
Label NCounterName =new Label();
NCounterName.Text = counter_txt.Text.ToString();
Label NCounterNumber = new Label();
NCounterNumber.Text = "0000";`enter code here`
}