.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 theRadTemplatedButton
is clicked. TheClicked
event handler receives two parameters:- The
sender
argument which is of typeRadTemplatedButton
. - An
EventArgs
object which provides information about theClicked
event.
- The
-
Pressed
—Raised whenRadTemplatedButton
is pressed (a finger presses on the buton, or a mouse button is pressed with a pointer positioned over the button). ThePressed
event handler receives two parameters:- The
sender
argument which is of typeRadTemplatedButton
. - An
EventHandler
object which provides information about thePressed
event.
- The
-
Released
—Raised when theRadTemplatedButton
is released (the finger or mouse button is released). TheReleased
event handler receives two parameters:- The
sender
argument which is of typeRadTemplatedButton
. - An
EventHandler
object which provides information about theReleased
event.
- The
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:
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:
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:
For a runnable example demonstrating the TemplatedButton Released event, see the SDKBrowser Demo Application and go to the TemplatedButton > Events category.