Back to Devexpress

AI Assistant Extensions

windowsforms-405153-ai-powered-extensions-ai-assistant.md

latest29.0 KB
Original Source

AI Assistant Extensions

  • Oct 09, 2025
  • 14 minutes to read

AI Assistant extensions allow you to enhance the way your users interact with and manage text content. These extensions leverage advanced natural language processing (NLP) technologies to offer automated, intelligent text manipulation capabilities directly within your Windows Forms applications.

Run Demo View Example: AI-powered Text Extensions

Applies To

Activate AI Assistant

Install DevExpress NuGet Packages

  1. DevExpress.AIIntegration.WinForms
  2. DevExpress.Win.Design (enables design-time features for DevExpress UI controls)

Read the following help topics for information on how to obtain the DevExpress NuGet Feed and install DevExpress NuGet packages:

Register AI Client

See the following help topic for information on required NuGet packages and system requirements: Register an AI Client.

The following code snippet registers the Azure OpenAI client:

csharp
using Microsoft.Extensions.AI;
using DevExpress.AIIntegration;

internal static class Program {
    [STAThread]
    static void Main() {
        Application.EnableVisualStyles();
        Application.SetCompatibleTextRenderingDefault(false);
        IChatClient azureChatClient = new Azure.AI.OpenAI.AzureOpenAIClient(new Uri(AzureOpenAIEndpoint),
            new System.ClientModel.ApiKeyCredential(AzureOpenAIKey))
            .GetChatClient(ModelId).AsIChatClient();
        AIExtensionsContainerDesktop.Default.RegisterChatClient(azureChatClient);
        // Uncomment the following line if your project targets the .NET Framework and
        // you create AI-powered behaviors in code.
        // DevExpress.AIIntegration.WinForms.BehaviorInitializer.Initialize();
        Application.Run(new Form1());
    }
    static string AzureOpenAIEndpoint { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT"); } }
    static string AzureOpenAIKey { get { return Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY"); } }
    static string ModelId { get { return "MODEL_NAME"; } }
}
vb
Imports Microsoft.Extensions.AI
Imports DevExpress.AIIntegration

Friend Module Program
    <STAThread>
    Sub Main()
        Application.EnableVisualStyles()
        Application.SetCompatibleTextRenderingDefault(False)
        ' Register Azure.OpenAI
        Dim azureChatClient As IChatClient = New Azure.AI.OpenAI.AzureOpenAIClient(New Uri(AzureOpenAIEndpoint),
            New System.ClientModel.ApiKeyCredential(AzureOpenAIKey)).
            GetChatClient(ModelId).AsIChatClient()
        AIExtensionsContainerDesktop.Default.RegisterChatClient(azureChatClient)
        ' Uncomment the following line if your project targets the .NET Framework and
        ' you create AI-powered behaviors in code.
        ' DevExpress.AIIntegration.WinForms.BehaviorInitializer.Initialize()
        Application.Run(New Form1())
    End Sub
    Private ReadOnly Property AzureOpenAIEndpoint() As String
        Get
            Return Environment.GetEnvironmentVariable("AZURE_OPENAI_ENDPOINT")
        End Get
    End Property
    Private ReadOnly Property AzureOpenAIKey() As String
        Get
            Return Environment.GetEnvironmentVariable("AZURE_OPENAI_APIKEY")
        End Get
    End Property
    Private ReadOnly Property ModelId As String
        Get
            Return "MODEL_NAME"
        End Get
    End Property
End Module

Create and Configure AI Assistant Behaviors

Follow the steps below to apply a behavior to a control at design time:

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

  2. Use the BehaviorManager’s smart tag menu to edit behaviors.

  3. Add required AI-powered text transform behaviors and configure their settings as needed.

  4. Run the application. Select the text in the MemoEdit and invoke the context menu. The context menu displays the AI Assistant submenu with AI-powered commands:

  5. Click the required command. The AI processes the command and generates an answer. The AI-generated answer is displayed in a dialog. A user can easily insert the answer directly into a document or text field with a single click.

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.BehaviorInitializer.Initialize();
        Application.Run(new Form1());
    }
}

Change Style

ChangeStyleBehavior rephrases or paraphrases the selected text while retaining its original meaning. This behavior allows you to generate alternative versions of the same content to match a specific genre or format. You can choose from 12 predefined styles (see WritingStyle).

The following code snippet registers a ChangeStyleBehavior and assigns it to a MemoEdit control. It uses the AI-powered extension to change style of the original text and obtain the result in English, regardless of the language used in the original text:

csharp
using DevExpress.AIIntegration.WinForms;

//...
public partial class Forms : DevExpress.XtraEditors.XtraForm {
    public MemoEdit() {
        InitializeComponent();
        behaviorManager1.Attach<ChangeStyleBehavior>(memoEdit1, behavior => {
            //behavior.Properties.Temperature = 0.6f;
            behavior.Properties.PromptAugmentation = "Always translate the result into English.";
        });
    }
}
vb
Imports DevExpress.AIIntegration.WinForms

'...
Partial Public Class Forms
    Inherits DevExpress.XtraEditors.XtraForm

    Private Function MemoEdit() As Public
        InitializeComponent()
        behaviorManager1.Attach(Of ChangeStyleBehavior)(memoEdit1, Sub(behavior)
            'behavior.Properties.Temperature = CSng(0.5)
            behavior.Properties.PromptAugmentation = "Always translate the result into English."
        End Sub)
    End Function
End Class

Tip

Use ChangeStyleRequest to manually initiate a request to change the style of the original text:

csharp
var response = await defaultAIExtensionsContainer.ChangeStyleAsync(
    new ChangeStyleRequest(originalText, WritingStyle.Academic)
);

Change Tone

ChangeToneBehavior adjusts the tone of the text to meet audience or context requirements. This option helps tailor the voice of your content.

Tone styles include:

  • Casual
  • Confident
  • Friendly
  • Professional
  • Straightforward

The following code snippet registers a ChangeToneBehavior and assigns it to a MemoEdit control:

csharp
using DevExpress.AIIntegration.WinForms;

//...
public partial class Forms : DevExpress.XtraEditors.XtraForm {
    public MemoEdit() {
        InitializeComponent();
        behaviorManager1.Attach<ChangeToneBehavior>(memoEdit1, behavior => {
            //behavior.Properties.Temperature = 0.6f;
            //behavior.Properties.PromptAugmentation = "Always translate the result into English.";
        });
    }
}
vb
Imports DevExpress.AIIntegration.WinForms

'...
Partial Public Class Forms
    Inherits DevExpress.XtraEditors.XtraForm

    Private Function MemoEdit() As Public
        InitializeComponent()
        behaviorManager1.Attach(Of ChangeToneBehavior)(memoEdit1, Sub(behavior)
            'behavior.Properties.Temperature = CSng(0.5)
            'behavior.Properties.PromptAugmentation = "Always translate the result into English."
        End Sub)
    End Function
End Class

Tip

Use ChangeToneRequest to manually initiate a request to adjust the tone of the original text:

csharp
var response = await defaultAIExtensionsContainer.ChangeToneAsync(
    new ChangeToneRequest(originalText, ToneStyle.Casual)
);

Expand

ExpandBehavior enriches your text with additional information or in-depth explanations.

The following code snippet registers an ExpandBehavior and assigns it to a MemoEdit control:

csharp
using DevExpress.AIIntegration.WinForms;

//...
public partial class Forms : DevExpress.XtraEditors.XtraForm {
    public MemoEdit() {
        InitializeComponent();
        behaviorManager1.Attach<ExpandBehavior>(memoEdit1, behavior => {
            //behavior.Properties.Temperature = 0.6f;
            //behavior.Properties.PromptAugmentation = "Always translate the result into English.";
        });
    }
}
vb
Imports DevExpress.AIIntegration.WinForms

'...
Partial Public Class Forms
    Inherits DevExpress.XtraEditors.XtraForm

    Private Function MemoEdit() As Public
        InitializeComponent()
        behaviorManager1.Attach(Of ExpandBehavior)(memoEdit1, Sub(behavior)
            'behavior.Properties.Temperature = CSng(0.5)
            'behavior.Properties.PromptAugmentation = "Always translate the result into English."
        End Sub)
    End Function
End Class

Tip

Use ExpandRequest to manually initiate a request to enrich the original text with additional information:

csharp
var response = await defaultAIExtensionsContainer.ExpandAsync(
    new ExpandRequest(originalText)
);

Explain

ExplainBehavior transforms text into more understandable terms that make complex content more accessible and understandable.

The following code snippet registers an ExplainBehavior and assigns it to a MemoEdit control:

csharp
using DevExpress.AIIntegration.WinForms;

//...
public partial class Forms : DevExpress.XtraEditors.XtraForm {
    public MemoEdit() {
        InitializeComponent();
        behaviorManager1.Attach<ExplainBehavior>(memoEdit1, behavior => {
            //behavior.Properties.Temperature = 0.6f;
            //behavior.Properties.PromptAugmentation = "Always translate the result into English.";
        });
    }
}
vb
Imports DevExpress.AIIntegration.WinForms

'...
Partial Public Class Forms
    Inherits DevExpress.XtraEditors.XtraForm

    Private Function MemoEdit() As Public
        InitializeComponent()
        behaviorManager1.Attach(Of ExplainBehavior)(memoEdit1, Sub(behavior)
            'behavior.Properties.Temperature = CSng(0.5)
            'behavior.Properties.PromptAugmentation = "Always translate the result into English."
        End Sub)
    End Function
End Class

Tip

Use ExplainRequest to manually initiate a request to explain the original text:

csharp
var response = await defaultAIExtensionsContainer.ExplainAsync(
    new ExplainRequest(originalText)
);

Proofread

ProofreadBehavior reviews the text for spelling, grammar, punctuation, and style errors.

The following code snippet registers a ProofreadBehavior and assigns it to a MemoEdit control:

csharp
using DevExpress.AIIntegration.WinForms;

//...
public partial class Forms : DevExpress.XtraEditors.XtraForm {
    public MemoEdit() {
        InitializeComponent();
        behaviorManager1.Attach<ProofreadBehavior>(memoEdit1, behavior => {
            //behavior.Properties.Temperature = 0.6f;
            //behavior.Properties.PromptAugmentation = "Always translate the result into English.";
        });
    }
}
vb
Imports DevExpress.AIIntegration.WinForms

'...
Partial Public Class Forms
    Inherits DevExpress.XtraEditors.XtraForm

    Private Function MemoEdit() As Public
        InitializeComponent()
        behaviorManager1.Attach(Of ProofreadBehavior)(memoEdit1, Sub(behavior)
            'behavior.Properties.Temperature = CSng(0.5)
            'behavior.Properties.PromptAugmentation = "Always translate the result into English."
        End Sub)
    End Function
End Class

Tip

Use ProofreadRequest to manually initiate a request to proofread the original text:

csharp
var response = await defaultAIExtensionsContainer.ProofreadAsync(
    new ProofreadRequest(originalText)
);

Shorten

ShortenBehavior removes unnecessary details and makes content more concise.

The following code snippet registers a ShortenBehavior and assigns it to a MemoEdit control:

csharp
using DevExpress.AIIntegration.WinForms;

//...
public partial class Forms : DevExpress.XtraEditors.XtraForm {
    public MemoEdit() {
        InitializeComponent();
        behaviorManager1.Attach<ShortenBehavior>(memoEdit1, behavior => {
            //behavior.Properties.Temperature = 0.6f;
            //behavior.Properties.PromptAugmentation = "Always translate the result into English.";
        });
    }
}
vb
Imports DevExpress.AIIntegration.WinForms

'...
Partial Public Class Forms
    Inherits DevExpress.XtraEditors.XtraForm

    Private Function MemoEdit() As Public
        InitializeComponent()
        behaviorManager1.Attach(Of ShortenBehavior)(memoEdit1, Sub(behavior)
            'behavior.Properties.Temperature = CSng(0.5)
            'behavior.Properties.PromptAugmentation = "Always translate the result into English."
        End Sub)
    End Function
End Class

Tip

Use ShortenRequest to manually initiate a request to shorten the original text:

csharp
var response = await defaultAIExtensionsContainer.ShortenAsync(
    new ShortenRequest(originalText)
);

Summarize

SummarizeBehavior generates a brief summary of long text.

SummarizeBehavior supports the following summarization modes:

  1. Abstractive Summarization

  2. Extractive Summarization

The following code snippet registers a SummarizeBehavior and assigns it to a MemoEdit control:

csharp
using DevExpress.AIIntegration;
using DevExpress.AIIntegration.WinForms;

//...
public partial class MemoEdit : DevExpress.XtraEditors.XtraForm {
    public MemoEdit() {
        InitializeComponent();
        behaviorManager1.Attach<SummarizeBehavior>(memoEdit1, behavior => {
            behavior.Properties.SummarizationMode = SummarizationMode.Extractive;
            behavior.Properties.PromptAugmentation = "Always translate the result into English.";
        });
    }
}
vb
Imports DevExpress.AIIntegration
Imports DevExpress.AIIntegration.WinForms

'...
Partial Public Class MemoEdit
    Inherits DevExpress.XtraEditors.XtraForm

    Public Sub New()
        InitializeComponent()
        behaviorManager1.Attach(Of SummarizeBehavior)(memoEdit1, Sub(behavior)
            behavior.Properties.SummarizationMode = SummarizationMode.Extractive
            behavior.Properties.PromptAugmentation = "Always translate the result into English."
        End Sub)
    End Sub
End Class

Tip

Use AbstractiveSummaryRequest and/or ExtractiveSummaryRequest to manually initiate a request to generate a summary for the original text:

csharp
var response1 = await defaultAIExtensionsContainer.AbstractiveSummaryAsync(
    new AbstractiveSummaryRequest(originalText)
);

var response2 = await defaultAIExtensionsContainer.ExtractiveSummaryAsync(
    new ExtractiveSummaryRequest(originalText)
);

Translate

TranslateBehavior converts the text from one language to another while maintaining the original meaning and context. Use the Languages parameter to specify target languages/cultures for text translation.

The following code snippet registers a TranslateBehavior and assigns it to a MemoEdit control:

csharp
using DevExpress.AIIntegration;
using DevExpress.AIIntegration.WinForms;
using DevExpress.AIIntegration.Desktop;

//...
public partial class MemoEdit : DevExpress.XtraEditors.XtraForm {
    public MemoEdit() {
        InitializeComponent();
            behaviorManager1.Attach<TranslateBehavior>(memoEdit1, behavior => {
                behavior.Properties.Languages = new LanguageInfo[] {
                    new LanguageInfo("de-DE"),
                    new LanguageInfo("es-ES")
                };
            });
    }
}
vb
Imports DevExpress.AIIntegration
Imports DevExpress.AIIntegration.WinForms
Imports DevExpress.AIIntegration.Desktop

'...
Partial Public Class MemoEdit
    Inherits DevExpress.XtraEditors.XtraForm

    Public Sub New()
        InitializeComponent()
            behaviorManager1.Attach(Of TranslateBehavior)(memoEdit1, Sub(behavior)
                behavior.Properties.Languages = New LanguageInfo() {
                    New LanguageInfo("de-DE"),
                    New LanguageInfo("es-ES")
                }
            End Sub)
    End Sub
End Class

Tip

Use TranslateRequest to manually initiate a request to translate the original text:

csharp
var response = await defaultAIExtensionsContainer.TranslateAsync(
    new TranslateRequest(textToTranslate, "Italian")
);

Ask AI Assistant (Custom Prompt)

CustomRequestBehavior displays the “Ask AI Assistant” item in the context menu. The “Ask AI Assistant” item invokes a dialog that allows users to interact with an AI-powered assistant directly within your application. A user can enter a question or prompt. The AI assistant will process the query and generate an answer.

The user can easily insert the answer directly into a document or text field with a single click. The user can insert the answer above/below the cursor, replace all content or selected text, or copy the answer to the clipboard.

Tip

Use CustomPromptRequest to manually initiate a request to transform the original text based on a custom request:

csharp
var response = await defaultAIExtensionsContainer.CustomPromptAsync(
    new CustomPromptRequest("Specify a prompt...", originalText)
);

Document Summarization

DocumentSummarizeBehavior generates a brief summary of long text contained in a document.

DocumentSummarizeBehavior supports the following summarization modes:

  1. Abstractive Summarization

  2. Extractive Summarization

The following code snippet registers a DocumentSummarizeBehavior and assigns it to the Document Viewer control:

csharp
using DevExpress.AIIntegration;
using DevExpress.AIIntegration.WinForms;
// ...
public partial class Form1 : Form {
    public Form1() {
        InitializeComponent();
            behaviorManager1.Attach<DocumentSummarizeBehavior>(documentViewer1, behavior => {
                behavior.Properties.SummarizationMode = SummarizationMode.Extractive;
            });
    }
}
vb
Imports DevExpress.AIIntegration
Imports DevExpress.AIIntegration.WinForms
' ...
Partial Public Class Form1
    Inherits Form

    Public Sub New()
        InitializeComponent()
            behaviorManager1.Attach(Of DocumentSummarizeBehavior)(documentViewer1, Sub(behavior)
                behavior.Properties.SummarizationMode = SummarizationMode.Extractive
            End Sub)
    End Sub
End Class

Review the following help topic for more information on how to use this functionality in the WinForms Document Viewer: Summarize and Translate Reports in the WinForms Document Viewer.

Document Translation

DocumentTranslateBehavior converts the text contained in a document from one language to another while maintaining the original meaning and context.

The following code snippet registers a DocumentTranslateBehavior and assigns it to the Document Viewer control:

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

    Public Sub New()
        InitializeComponent()
            behaviorManager1.Attach(Of DocumentTranslateBehavior)(documentViewer1, Sub(behavior)
                behavior.Properties.Languages = New LanguageInfo() {
                    New LanguageInfo("de-DE"),
                    New LanguageInfo("es-ES")
                }
            End Sub)
    End Sub
End Class

Review the following help topic for more information on how to use this functionality in the WinForms Document Viewer: Summarize and Translate Reports in the WinForms Document Viewer.

Inline Document Translation

DocumentTranslateInlineBehavior converts the text contained in a document from one language to another on the document preview. Unlike DocumentTranslateBehavior, the Translate Inline command translates text directly on the document preview without additional dialogs. You can export or print the translated document.

The following code snippet registers a DocumentTranslateBehavior and assigns it to the 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

Review the following help topic for more information on how to use this functionality in the WinForms Document Viewer: Translate Reports Inline in the WinForms Document Viewer.

Temperature

The Temperature parameter controls the balance between creativity and consistency in AI responses. Lower temperatures yield more predictable and focused outputs, while higher temperatures produce more diverse and creative responses.

The Temperature parameter is predefined for DevExpress AI-powered behaviors.

AI-powered BehaviorTemperature (Default)
Summarize Behavior1
Change Style Behavior0.6
Change Tone Behavior0.5
Translate Behavior0.5
Proofread Behavior0.2
Expand Behavior
Explain Behavior
Shorten Behavior

Prompt Augmentation

DevExpress AI-powered extensions allow you to specify additional instructions that modify the default prompt before processing. Prompt augmentation improves the relevance and accuracy of the AI’s response. Use the PromptAugmentation property to specify additional instructions.

The following code snippet registers a ChangeStyleBehavior and assigns it to a MemoEdit control. It uses the AI-powered extension to change style of the original text and obtain the result in English, regardless of the language used in the original text:

csharp
using DevExpress.AIIntegration.WinForms;

//...
public partial class Forms : DevExpress.XtraEditors.XtraForm {
    public MemoEdit() {
        InitializeComponent();
        behaviorManager1.Attach<ChangeStyleBehavior>(memoEdit1, behavior => {
            //behavior.Properties.Temperature = 0.6f;
            behavior.Properties.PromptAugmentation = "Always translate the result into English.";
        });
    }
}
vb
Imports DevExpress.AIIntegration.WinForms

'...
Partial Public Class Forms
    Inherits DevExpress.XtraEditors.XtraForm

    Private Function MemoEdit() As Public
        InitializeComponent()
        behaviorManager1.Attach(Of ChangeStyleBehavior)(memoEdit1, Sub(behavior)
            'behavior.Properties.Temperature = CSng(0.5)
            behavior.Properties.PromptAugmentation = "Always translate the result into English."
        End Sub)
    End Function
End Class

Chunking (Processing Long Input Text)

If input text is too long, the DevExpress control displays a dialog that informs a user that the input text must be divided into manageable chunks to ensure accurate processing.

The user can process chunks one by one by pressing the “Proceed” button, or enable the “I consent to process all remaining chunks” option to process all chunks automatically.

After processing, chunks are reassembled into a single output.

Tip

Use the ChunkMaxLength property to specify how much text can be processed simultaneously. The chunk length is limited by 6,000 symbols. The TextBufferMaxSize property specifies the maximum size of the input text, in bytes.

See Also

Smart Search AI-powered Extension

Smart Paste AI-powered Extension

DevExpress AI-powered Extensions for WinForms