O'Reilly logo

Windows Application Development Cookbook by Marcin Jamro

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Adding controls programmatically

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.

Getting ready

To step through this recipe, you only need the automatically generated project.

How to do it...

To add a button and adjust its appearance programmatically, perform the following steps:

  1. Specify the name of the Grid control by modifying the content of the MainPage.xaml file as follows:
            <Page (...)> 
                <Grid 
                    Name="Grid" Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> </Grid> </Page> ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required