For clarity, the following code shows you how the previous example would look in C#:
public class MainPage : ContentPage
{
}
page is a class that inherits from Xamarin.Forms.ContentPage. This class is automatically generated for us if we create an XAML page, but if we just use code, we will need to define it ourself.
Let's create the same control hierarchy as the XAML page we defined earlier using the following code:
var page = new MainPage();
var stacklayout = new StackLayout();
stacklayout.Children.Add(
new Label()
{
Text = "Welcome to Xamarin.Forms"
});
page.Content = stacklayout;
The first statement creates a page object. We could, in theory, create a new ContentPage page directly, but this would prohibit us from writing any code behind it. For this reason, it's good practice to subclass each page that we plan to create.
The block following this first statement creates...