Back to Devexpress

Translate Reports Inline in the WinForms Document Viewer

xtrareports-405450-ai-powered-functionality-desktop-reporting-document-translate-inline-win-viewer.md

latest7.2 KB
Original Source

Translate Reports Inline in the WinForms Document Viewer

  • Nov 24, 2025
  • 4 minutes to read

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

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 AI Assistant

Install NuGet Packages

Install the following NuGet packages:

Optional:

  • DevExpress.Win.Design (for .NET projects)

Register 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;

internal static class Program {
    static string AzureOpenAIEndpoint { get { return "AZURE_OPENAI_ENDPOINT"; } }
    static string AzureOpenAIKey { get { return "AZURE_OPENAI_APIKEY"; } }
    static string DeploymentName { get { return "MODEL_NAME"; } } // For example, gpt-4.1.
    [STAThread]
    static void Main(){
        IChatClient client = new AzureOpenAIClient(
            new Uri(AzureOpenAIEndpoint),
            new ApiKeyCredential(AzureOpenAIKey))
                .GetChatClient(DeploymentName).AsIChatClient(); 
        AIExtensionsContainerDesktop.Default.RegisterChatClient(client);
        ApplicationConfiguration.Initialize();
        Application.Run(new Form1());
    }
}
vb
Imports Azure.AI.OpenAI
Imports DevExpress.AIIntegration
Imports Microsoft.Extensions.AI
Imports System.ClientModel

Friend Module Program
    Private ReadOnly Property AzureOpenAIEndpoint() As String
        Get
            Return "AZURE_OPENAI_ENDPOINT"
        End Get
    End Property
    Private ReadOnly Property AzureOpenAIKey() As String
        Get
            Return "AZURE_OPENAI_APIKEY"
        End Get
    End Property
    Private ReadOnly Property DeploymentName() As String
        Get
            Return "MODEL_NAME"
        End Get
    End Property
        <STAThread>
        Sub Main()
        Dim client As IChatClient = (New AzureOpenAIClient(New Uri(AzureOpenAIEndpoint), New ApiKeyCredential(AzureOpenAIKey))).GetChatClient(DeploymentName).AsIChatClient()
        AIExtensionsContainerDesktop.Default.RegisterChatClient(client)
        ApplicationConfiguration.Initialize()
        Application.Run(New Form1())
        End Sub
End Module

Tip

How to Register OpenAI, Azure OpenAI, Ollama, and Semantic Kernel Clients.

Add a Document Viewer

  1. Drop the DocumentViewer component from the Toolbox onto a Form.

  2. Click the smart tag and select Create Ribbon Toolbar or Create Standard Toolbar. Both these actions generate the context menu where users can access the Translate Inline functionality.

  3. Specify the Document Source option. Use an object that supplies a document to the Document Viewer.

Create and Configure AI Assistant Behaviors

  1. Drop the BehaviorManager component from the Toolbox onto a Form.

  2. (For .NET Framework Projects) Use the Register AI-Powered Behaviors option in the BehaviorManager’s smart tag menu to add the “AI-Powered Behaviors” submenu with report behaviors to BehaviorManager.

  3. Use the Edit Behaviors option in the BehaviorManager’s smart tag menu to access the behavior collection.

  4. Add the Translate Inline Behavior and configure its settings:

Create and Configure AI Assistant Behavior at Runtime

The following code registers a DocumentTranslateInlineBehavior and attaches it to the WinForms Document Viewer control:

csharp
using DevExpress.AIIntegration;
using DevExpress.AIIntegration.WinForms;
// ...
public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
            behaviorManager1.Attach<DocumentTranslateInlineBehavior>(documentViewer1, behavior => {
                behavior.Properties.Languages = new LanguageInfo[] {
                    new LanguageInfo("de-DE")
                };
            });
    }
}
vb
Imports DevExpress.AIIntegration
Imports DevExpress.AIIntegration.WinForms
' ...
Partial Public Class Form1
    Inherits Form
    Public Sub New()
        InitializeComponent()
            behaviorManager1.Attach(Of DocumentTranslateInlineBehavior)(documentViewer1, Sub(behavior)
                behavior.Properties.Languages = New LanguageInfo() {
                    New LanguageInfo("de-DE")
                }
            End Sub)
    End Sub
End Class

Note

Call the BehaviorInitializer.Initialize() method at application startup if your project targets the .NET Framework and you create AI-powered behaviors in code. Otherwise, an exception is thrown.

csharp
internal static class Program {
    [STAThread]
    static void Main() {
        //...
        // The Initialize() method forcibly initializes the behavior manager in .NET Framework apps.
        DevExpress.AIIntegration.WinForms.Reporting.BehaviorInitializer.Initialize();
        Application.Run(new Form1());
    }
}

Translate a Report Document

You can access the Translate Inline command in the AI context menu of WinForms Document Viewer.

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 at the 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?”