Button

The Button view reacts to click events.

Define in XAML

<Button Text="Login" />

Define in Code

var button = new Button
{
    Text = "Login"
};

Add a Click Event

We can attach a Click event to the Button in XAML and define a function in the backing code file with the function to handle the Button click event as follows :

In XAML

<Button Text="Login" Clicked="OnLoginButtonClicked" />

In Backing Code File

void OnLoginButtonClicked(object sender, System.EventArgs e)
{
    //Do something
}

Define the Click Event in Code

We can define the Button in XAML and attach the Click event in code. The Button will need be named in XAML. We can give names to controls in XAML using the extension x:Name as following :

<Button Text="Login" x:Name="btnLogin" />

The x:Name is a namespace defined on the XAML page.

Wire Event in Code

We can then used the variable defined in the XAML file and wire up the event as follows :

btnLogin.Clicked += (sender, e) => {
    //Do something
};

results matching ""

    No results matching ""