You have learned how to use the XAML language to place controls on the page and configure them. However, it does not mean that controls must only be created in a declarative way using XAML. In this recipe, you will learn how to create a button and add it to the Grid
control programmatically, using the C# language.
To add a button and adjust its appearance programmatically, perform the following steps:
Specify the name of the
Grid
control by modifying the content of theMainPage.xaml
file as follows:<Page (...)> <Grid Name="Grid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> </Grid> </Page>
Create and configure a new button and add it to the
Grid
control by modifying the constructor...