Back to Devexpress

Translate Reports Inline in the WPF Document Preview

xtrareports-405609-ai-powered-functionality-desktop-reporting-document-translate-inline-wpf-viewer.md

latest7.4 KB
Original Source

Translate Reports Inline in the WPF Document Preview

  • Nov 28, 2025
  • 3 minutes to read

This help topic describes how to integrate the AI-powered Translate Inline command into the WPF Document Preview.

Unlike the Translate command, Translate Inline translates text directly on the document preview without additional dialogs. You can export or print the translated document.

Activate an AI Assistant

Install NuGet Packages

Install the following NuGet packages:

The following tutorial uses Azure OpenAI. Refer to the requirements section for information about NuGet packages required for other supported AI services.

Register an AI Client

The following code snippet registers an Azure OpenAI client at application startup:

csharp
using Azure.AI.OpenAI;
using DevExpress.AIIntegration;
using Microsoft.Extensions.AI;
using System.ClientModel;
// ...
public partial class App : Application {
    static string AzureOpenAIEndpoint { get { return "AZURE_OPENAI_ENDPOINT"; } }
    static string AzureOpenAIKey { get { return "AZURE_OPENAI_APIKEY"; } }
    static string DeploymentName { get { return "gpt-4o-mini"; } }

    public App() {
        IChatClient chatClient = new AzureOpenAIClient(
           new Uri(AzureOpenAIEndpoint),
           new ApiKeyCredential(AzureOpenAIKey))
               .GetChatClient(DeploymentName).AsIChatClient();
        AIExtensionsContainerDesktop.Default.RegisterChatClient(chatClient);
    }
}
vb
Imports Azure.AI.OpenAI
Imports DevExpress.AIIntegration
Imports Microsoft.Extensions.AI
Imports System.ClientModel
' ...
Partial Public Class App
    Inherits Application
    Private Shared ReadOnly Property AzureOpenAIEndpoint() As String
        Get
            Return "AZURE_OPENAI_ENDPOINT"
        End Get
    End Property
    Private Shared ReadOnly Property AzureOpenAIKey() As String
        Get
            Return "AZURE_OPENAI_APIKEY"
        End Get
    End Property
    Private Shared ReadOnly Property DeploymentName() As String
        Get
            Return "gpt-4o-mini"
        End Get
    End Property
    Public Sub New()
        Dim chatClient As IChatClient = (New AzureOpenAIClient(New Uri(AzureOpenAIEndpoint), New ApiKeyCredential(AzureOpenAIKey))).GetChatClient(DeploymentName).AsIChatClient()
        AIExtensionsContainerDesktop.Default.RegisterChatClient(chatClient)
    End Sub
End Class

Note

Review the following help topic for information on how to register other supported AI services: Register AI Clients.

Create and Configure AI Assistant Behaviors

Register DocumentTranslateInlineBehavior, specify its settings, and assign the behavior to the Document Preview control.

The following settings are available:

LanguagesSpecifies a collection of target languages for text translation.TemperatureSpecifies the balance between creativity and consistency in AI responses.PromptAugmentationSpecifies additional instructions that modify the prompt before processing.

Markup:

xaml
xmlns:dxp="http://schemas.devexpress.com/winfx/2008/xaml/printing" 
xmlns:dxai="http://schemas.devexpress.com/winfx/2008/xaml/ai" 
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"  
... 
<dxp:DocumentPreviewControl Name="preview"> 
    <dxmvvm:Interaction.Behaviors> 
        <dxai:DocumentTranslateInlineBehavior>
            <dxai:LanguageInfo Culture="de-DE"/> 
        </dxai:DocumentTranslateInlineBehavior>
    </dxmvvm:Interaction.Behaviors> 
</dxp:DocumentPreviewControl>

Code-Behind:

csharp
using System.Collections.Generic;
using System.Globalization;
using DevExpress.AIIntegration;
using DevExpress.AIIntegration.Wpf;
using DevExpress.Mvvm.UI.Interactivity;
// ...
public partial class MainWindow : Window {
    public MainWindow() {
        InitializeComponent();
        AddAIBehaviors();
    }
    void AddAIBehavior() {
        var translateBehavior = new DocumentTranslateInlineBehavior() {
            Languages = new List<LanguageInfo>() {
                new LanguageInfo() { Culture = new CultureInfo("de-DE") }
            }
        };
        var behavior = Interaction.GetBehaviors(preview);
        behavior.Add(translateBehavior);
    }
}
vb
Imports System.Collections.Generic
Imports System.Globalization
Imports DevExpress.AIIntegration
Imports DevExpress.AIIntegration.Wpf
Imports DevExpress.Mvvm.UI.Interactivity
' ...
Partial Public Class MainWindow
    Inherits Window

    Public Sub New()
        InitializeComponent()
        AddAIBehaviors()
    End Sub
    Private Sub AddAIBehavior()
        Dim translateBehavior = New DocumentTranslateInlineBehavior() With {
            .Languages = New List(Of LanguageInfo)() From {
                New LanguageInfo() With {.Culture = New CultureInfo("de-DE")}
            }
        }
        Dim behavior = Interaction.GetBehaviors(preview)
        behavior.Add(translateBehavior)
    End Sub
End Class

Translate a Report Document

You can access the Translate Inline command in the AI context menu of WPF Document Preview.

Right-click on an opened report or selected report content. Select Translate Inline from the AI Assistant submenu. Select input text range (selected content, document page, or entire document) and the target language.

The “AI-Generated Translation” label appears next to the report’s top-left corner once the translation is completed:

Click Revert to Original in the AI Assistant submenu to cancel translation:

The following message appears when you export a document with an AI-generated translation:

“You are about to export a document that contains AI-generated translations. Do you want to proceed?”