New to Telerik UI for .NET MAUIStart a free 30-day trial

Getting Started with the .NET MAUI SmartPasteButton

Updated on Apr 16, 2026

This guide provides the information you need to start using the Telerik UI for .NET MAUI SmartPasteButton by adding the control to your project.

The following image shows the default look of the RadSmartPasteButton control:

.NET MAUI SmartPasteButton Getting Started

Prerequisites

Before adding the SmartPasteButton, you need to:

  1. Install.NET9 or later.

  2. Set up your .NET MAUI application.

  3. Download Telerik UI for .NET MAUI.

  4. Install Telerik UI for .NET MAUI.

  5. Install an AI provider. For example Azure OpenAI or OpenAI, etc.

Step 1: Configure the AI Service

  1. Install the Telerik.AI.SmartComponents.Extensions package in your .NET MAUI project.
script
dotnet add package Telerik.AI.SmartComponents.Extensions

The Telerik.AI.SmartComponents.Extensions package has a dependency on the Microsoft.Extensions.AI package.

  1. Configure the AI services in your application. This typically involves setting up an AI provider (such as Azure OpenAI, OpenAI, etc.) and providing the necessary API keys or credentials.

  2. Register the AI service and AI chat client in your application.

    For the example, we will use the Azure.AI.OpenAI and Microsoft.Extensions.AI.OpenAI packages. Add the packages to your project. To register the AI service and chat client, the following code is needed in MauiProgram.cs:

    C#
    builder.Services.AddSingleton(sp =>
    {
        return new AzureOpenAIClient(new Uri("AZURE_OPENAI_ENDPOINT"), new AzureKeyCredential("AZURE_OPENAI_API_KEY"));
    });
    
    builder.Services.AddChatClient(services =>
        services.GetRequiredService<AzureOpenAIClient>().GetChatClient("gpt-4.1").AsIChatClient()
    );

Step 2: Process the Smart Paste Request

Inside the SmartPasteRequest event handler or in the command that processes the smart paste request, you need to create a SmartPasteRequest object with the content and form fields from the event arguments, send it to your AI service, and set the response back to the event arguments.

Here is an example of how to do this:

C#
private async void OnSmartPasteRequest(object sender, SmartPasteButtonRequestContext e)
{
    try
    {
        var chatClient = Application.Current.Handler.MauiContext.Services.GetRequiredService<IChatClient>();

        var request = new SmartPasteRequest
        {
            Content = e.Content,
            FormFields = e.Fields.Select(f => new SmartPasteFormField
            {
                Field = f.Field,
                Description = f.Description,
                AllowedValues = f.AllowedValues,
                Type = f.Type
            }).ToArray()
        };

        List<ChatMessage> conversationMessages = request.GetChatMessages();
        ChatResponse completion = await chatClient.GetResponseAsync(conversationMessages, new ChatOptions(), e.CancellationToken);
        e.SetResponse(completion.ExtractSmartPasteResponse().FieldValues);
    }
    catch (OperationCanceledException)
    {
        e.Cancel();
    }
    catch (Exception ex)
    {
        await ShowErrorAsync($"Smart paste failed: {ex.Message}");
        e.SetError(ex);
    }
}

Review the Integration with External UI article for more details how to integrate the Telerik SmartPasteButton for .NET MAUI with external UI components to enhance user experience.

Example with SmartPasteButton and DataForm

1. Define the SmartPasteButton control to your page:

XAML
<telerik:RadSmartPasteButton Provider="{x:Reference dataForm}"
                             SmartPasteRequest="OnSmartPasteRequest" />

2. Add the DataForm control to your page. The SmartPasteButton is designed to work with the DataForm control, allowing you to populate form fields with structured data extracted from unstructured text. By integrating the SmartPasteButton with the DataForm, you can enhance the user experience and streamline data entry processes within your application.

XAML
<telerik:RadDataForm x:Name="dataForm"
                     AutoGenerateItems="False" 
                     Grid.Row="1">
    <telerik:RadDataForm.BindingContext>
        <local:Profile />
    </telerik:RadDataForm.BindingContext>
    <telerik:DataFormRadEntryEditor PropertyName="Name" />
    <telerik:DataFormRadEmailMaskedEditor PropertyName="Email" />
    <telerik:DataFormRadEntryEditor PropertyName="JobTitle" />
    <telerik:DataFormRadEntryEditor PropertyName="Address" />
</telerik:RadDataForm>

3. Text from the clipboard is used for the smart paste operation.

XAML
<telerik:RadTemplatedButton Content="Copy To Clipboard"
                            Clicked="OnCopyFromClipboardClicked"/>

4. Add the telerik namespace:

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

5. Define the copy button's Clicked event handler:

C#
private async void OnCopyFromClipboardClicked(object sender, System.EventArgs e)
{
    if (!string.IsNullOrEmpty(this.label.Text))
    {
        await Clipboard.SetTextAsync(this.label.Text);
    }
}

6. The SmartPasteRequest event handler:

C#
private async void OnSmartPasteRequest(object sender, SmartPasteButtonRequestContext e)
{
    try
    {
        var request = new { Content = e.Content, FormFields = e.Fields };
        var httpResponse = await new HttpClient().PostAsJsonAsync(
            "https://demos.telerik.com/service/v2/ai/smartpaste/smartpaste",
            request,
            e.CancellationToken);
        httpResponse.EnsureSuccessStatusCode();

        var response = await httpResponse.Content.ReadFromJsonAsync<SmartPasteResponse>(e.CancellationToken);
        e.SetResponse(response.FieldValues);
    }
    catch (OperationCanceledException)
    {
        e.Cancel();
    }
    catch (Exception ex)
    {
        e.SetError(ex);
    }
}

7. Register the Telerik controls through the Telerik.Maui.Controls.Compatibility.UseTelerik extension method called inside the CreateMauiApp method of the MauiProgram.cs file of your project:

C#
using Telerik.Maui.Controls.Compatibility;
public static class MauiProgram
{
	public static MauiApp CreateMauiApp()
	{
		var builder = MauiApp.CreateBuilder();
		builder
			.UseTelerik()
			.UseMauiApp<App>()
			.ConfigureFonts(fonts =>
			{
				fonts.AddFont("OpenSans-Regular.ttf", "OpenSansRegular");
			});
		return builder.Build();
	}
}

The SmartPasteButton examples in the SDKBrowser Demo Application use a Telerik-hosted AI service for demonstration purposes only.

To use the smart paste functionality in your application, you must configure your own AI service.

How to do that is described in the Configuration article.

For a runnable example with the SmartPasteButton Getting Started scenario, see the SDKBrowser Demo Application and go to SmartPasteButton > Getting Started.

Additional Resources

See Also