.NET MAUI SmartPasteButton Integration with DataForm
The SmartPasteButton control has an integration 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.
To integrate the SmartPasteButton with the DataForm, you need to set the Provider property of the SmartPasteButton to reference the DataForm instance. This allows the SmartPasteButton to extract structured information from the clipboard content and populate the corresponding fields in the DataForm based on the form structure.
The following snippet shows how to set the Provider property of the SmartPasteButton to reference a DataForm instance in XAML:
<telerik:RadDataForm x:Name="dataForm" ... />
<telerik:RadSmartPasteButton Provider="{x:Reference dataForm}" ... />
The following example demonstrates the SmartPasteButton and DataForm integration:
1. Define the DataForm and the SmartPasteButton controls on the page:
<telerik:RadSmartPasteButton Provider="{x:Reference dataForm}"
SmartPasteRequest="OnSmartPasteRequest" />
2. Add the DataForm control to your page. The SmartPasteButton is designed to work in conjunction with the DataForm control, allowing you to easily 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.
<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.
<telerik:RadTemplatedButton Content="Copy To Clipboard"
Clicked="OnCopyFromClipboardClicked"/>
4. Add the telerik namespace:
xmlns:telerik="http://schemas.telerik.com/2022/xaml/maui"
5. Define the copy button's Clicked event handler:
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:
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);
}
}

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 Integration with DataForm, see the SDKBrowser Demo Application and go to SmartPasteButton > Getting Started.