New to Telerik UI for .NET MAUI? Start a free 30-day trial

.NET MAUI TemplatedButton Events

The .NET MAUI TemplatedButton emits a set of events that allow you to configure the component's behavior in response to specific user actions.

The .NET MAUI TemplatedButton exposes the following events:

  • Clicked—Raised when the RadTemplatedButton is clicked. The Clicked event handler receives two parameters:

    • The sender argument which is of type RadTemplatedButton.
    • An EventArgs object which provides information about the Clicked event.
  • Pressed—Raised when RadTemplatedButton is pressed (a finger presses on the buton, or a mouse button is pressed with a pointer positioned over the button). The Pressed event handler receives two parameters:

    • The sender argument which is of type RadTemplatedButton.
    • An EventHandler object which provides information about the Pressed event.
  • Released—Raised when the RadTemplatedButton is released (the finger or mouse button is released). The Released event handler receives two parameters:

    • The sender argument which is of type RadTemplatedButton.
    • An EventHandler object which provides information about the Released event.

Using the Clicked Event

The following example demonstrates how to use the Clicked event.

1. Define the button in XAML:

<telerik:RadTemplatedButton x:Name="templatedButton"
                            Content="My Button"
                            Clicked="OnRadTemplatedButtonClicked" />
<Label x:Name="label" Text="TemplatedButton is clicked 0 times" />

2. Add the telerik namespace:

xmlns:telerik="http://schemas.telerik.com/2022/xaml/maui"

3. Add the Clicked event:

private void OnRadTemplatedButtonClicked(object sender, System.EventArgs e)
{
    count++;

    if (count == 1)
    {
        this.label.Text = $"TemplatedButton is clicked {count} time";
    }
    else
    {
        this.label.Text = $"TemplatedButton is clicked {count} times";
    }
}

This is the result on WinUI:

.NET MAUI TemplatedButton Clicked Event

For a runnable example demonstrating the TemplatedButton Clicked event, see the SDKBrowser Demo Application and go to the TemplatedButton > Events category.

Using the Pressed Event

The following example demonstrates how to use the Pressed event.

1. Define the button in XAML:

<telerik:RadTemplatedButton x:Name="templatedButton" 
                            Content="My Templated Button" 
                            Pressed="OnTemplatedButtonPressed" />
<Label x:Name="label" Text="TemplatedButton is pressed 0 times" />

2. Add the telerik namespace:

xmlns:telerik="http://schemas.telerik.com/2022/xaml/maui"

3. Add the Pressed event:

private void OnTemplatedButtonPressed(object sender, System.EventArgs e)
{
    count++;

    if (count == 1)
    {
        this.label.Text = $"TemplatedButton is pressed {count} time";
    }
    else
    {
        this.label.Text = $"TemplatedButton is pressed {count} times";
    }
}

This is the result on WinUI:

.NET MAUI TemplatedButton Pressed Event

For a runnable example demonstrating the TemplatedButton Pressed event, see the SDKBrowser Demo Application and go to the TemplatedButton > Events category.

Using the Released Event

The following example demonstrates how to use the Released event.

1. Define the button in XAML:

<telerik:RadTemplatedButton x:Name="templatedButton" 
                            Content="My Button" 
                            Released="OnTemplatedButtonReleased" />
<Label x:Name="label" Text="TemplatedButton is released 0 times" />

2. Add the telerik namespace:

xmlns:telerik="http://schemas.telerik.com/2022/xaml/maui"

3. Add the Released event:

private void OnTemplatedButtonReleased(object sender, System.EventArgs e)
{
    count++;

    if (count == 1)
    {
        this.label.Text = $"TemplatedButton is released {count} time";
    }
    else
    {
        this.label.Text = $"TemplatedButton is released {count} times";
    }
}

This is the result on WinUI:

.NET MAUI TemplatedButton Released Event

For a runnable example demonstrating the TemplatedButton Released event, see the SDKBrowser Demo Application and go to the TemplatedButton > Events category.

See Also

In this article