AI Assistant Extensions
- 6 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 WPF applications.
Applies To
Activate AI Assistant
1. Install DevExpress NuGet Packages
DevExpress.AIIntegration.Wpf
DevExpress.Wpf
Read the following help topics for information on how to obtain the DevExpress NuGet Feed and install DevExpress NuGet packages:
- Choose Between Offline and Online DevExpress NuGet Feeds
- Install NuGet Packages in Visual Studio, VS Code, and Rider
2. Register AI Client
The following code snippet registers an Azure OpenAI client at application startup within the AIExtensionsContainerDesktop container:
using Azure.AI.OpenAI;
using DevExpress.AIIntegration;
using DevExpress.Xpf.Core;
using Microsoft.Extensions.AI;
using System;
using System.Windows;
namespace AIAssistantApp {
public partial class App : Application {
static App() {
CompatibilitySettings.UseLightweightThemes = true;
}
protected override void OnStartup(StartupEventArgs e) {
base.OnStartup(e);
ApplicationThemeHelper.ApplicationThemeName = "Win11Light";
IChatClient asChatClient = new AzureOpenAIClient(new Uri(AzureOpenAIEndpoint),
new System.ClientModel.ApiKeyCredential(AzureOpenAIKey))
.AsChatClient("GPT4o");
AIExtensionsContainerDesktop.Default.RegisterChatClient(asChatClient);
}
}
}
Tip
Read the following help topic for additional information: How to Register an AI Client.
3. Create and Configure AI Assistant Behaviors
To enable AI-powered functionality in a DevExpress WPF control, add mvvm
and ai
namespaces to the Window
and attach the required AI-powered behaviors to the control.
The following example activates Change Style, Proofread, and Translate AI-powered extensions in a TextEdit control:
<dx:ThemedWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
xmlns:dxai="http://schemas.devexpress.com/winfx/2008/xaml/ai"
x:Class="AIAssistant.MainWindow"
Title="MainWindow" Height="800" Width="800">
<Grid>
<dxe:TextEdit TextWrapping="Wrap" AcceptsReturn="True" VerticalContentAlignment="Top">
<dxmvvm:Interaction.Behaviors>
<dxai:ChangeStyleBehavior x:Name="ChangeStyle"/>
<dxai:ProofreadBehavior x:Name="Proofread"/>
<dxai:TranslateBehavior x:Name="Translate">
<dxai:LanguageInfo Culture="de-DE"/>
<dxai:LanguageInfo Culture="es-ES"/>
</dxai:TranslateBehavior>
</dxmvvm:Interaction.Behaviors>
</dxe:TextEdit>
</Grid>
</dx:ThemedWindow>
4. Define Shortcuts and Bind Commands
The following example defines a Ctrl+Space shortcut that executes the Shorten AI-powered extension. The example also defines a similar command for the button.
<dx:ThemedWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
xmlns:dxai="http://schemas.devexpress.com/winfx/2008/xaml/ai"
x:Class="AIAssistant.MainWindow"
Title="MainWindow" Height="800" Width="800">
<Grid>
<dxe:TextEdit TextWrapping="Wrap" AcceptsReturn="True" VerticalContentAlignment="Top">
<dxmvvm:Interaction.Behaviors>
<dxai:ShortenBehavior x:Name="Shorten"/>
</dxmvvm:Interaction.Behaviors>
<dxe:TextEdit.InputBindings>
<KeyBinding Gesture="Ctrl+Space"
Command="{Binding ElementName=Shorten, Path=ShortenCommand}"/>
</dxe:TextEdit.InputBindings>
</dxe:TextEdit>
<Button Content="Shorten Selected Text"
Command="{Binding ElementName=Shorten, Path=ShortenCommand}"/>
</Grid>
</dx:ThemedWindow>
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 example activates the AI-powered “Change Style” extension in a TextEdit control:
<dx:ThemedWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
xmlns:dxai="http://schemas.devexpress.com/winfx/2008/xaml/ai"
x:Class="AIAssistant.MainWindow"
Title="MainWindow" Height="800" Width="800">
<Grid>
<dxe:TextEdit TextWrapping="Wrap" AcceptsReturn="True" VerticalContentAlignment="Top">
<dxmvvm:Interaction.Behaviors>
<dxai:ChangeStyleBehavior x:Name="ChangeStyle"/>
</dxmvvm:Interaction.Behaviors>
</dxe:TextEdit>
</Grid>
</dx:ThemedWindow>
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 example activates the AI-powered “Change Tone” extension in a TextEdit control:
<dx:ThemedWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
xmlns:dxai="http://schemas.devexpress.com/winfx/2008/xaml/ai"
x:Class="AIAssistant.MainWindow"
Title="MainWindow" Height="800" Width="800">
<Grid>
<dxe:TextEdit TextWrapping="Wrap" AcceptsReturn="True" VerticalContentAlignment="Top">
<dxmvvm:Interaction.Behaviors>
<dxai:ChangeToneBehavior x:Name="ChangeTone"/>
</dxmvvm:Interaction.Behaviors>
</dxe:TextEdit>
</Grid>
</dx:ThemedWindow>
Expand
ExpandBehavior enriches your text with additional information or in-depth explanations.
The following example activates the AI-powered “Expand” extension in a TextEdit control:
<dx:ThemedWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
xmlns:dxai="http://schemas.devexpress.com/winfx/2008/xaml/ai"
x:Class="AIAssistant.MainWindow"
Title="MainWindow" Height="800" Width="800">
<Grid>
<dxe:TextEdit TextWrapping="Wrap" AcceptsReturn="True" VerticalContentAlignment="Top">
<dxmvvm:Interaction.Behaviors>
<dxai:ExpandBehavior x:Name="Expand"/>
</dxmvvm:Interaction.Behaviors>
</dxe:TextEdit>
</Grid>
</dx:ThemedWindow>
Explain
ExplainBehavior transforms text into more understandable terms that make complex content more accessible and understandable.
The following example activates the AI-powered “Explain” extension in a TextEdit control:
<dx:ThemedWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
xmlns:dxai="http://schemas.devexpress.com/winfx/2008/xaml/ai"
x:Class="AIAssistant.MainWindow"
Title="MainWindow" Height="800" Width="800">
<Grid>
<dxe:TextEdit TextWrapping="Wrap" AcceptsReturn="True" VerticalContentAlignment="Top">
<dxmvvm:Interaction.Behaviors>
<dxai:ExplainBehavior x:Name="Explain"/>
</dxmvvm:Interaction.Behaviors>
</dxe:TextEdit>
</Grid>
</dx:ThemedWindow>
Proofread
ProofreadBehavior reviews the text for spelling, grammar, punctuation, and style errors.
The following example activates the AI-powered “Proofread” extension in a TextEdit control:
<dx:ThemedWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
xmlns:dxai="http://schemas.devexpress.com/winfx/2008/xaml/ai"
x:Class="AIAssistant.MainWindow"
Title="MainWindow" Height="800" Width="800">
<Grid>
<dxe:TextEdit TextWrapping="Wrap" AcceptsReturn="True" VerticalContentAlignment="Top">
<dxmvvm:Interaction.Behaviors>
<dxai:ProofreadBehavior x:Name="Proofread"/>
</dxmvvm:Interaction.Behaviors>
</dxe:TextEdit>
</Grid>
</dx:ThemedWindow>
Shorten
ShortenBehavior removes unnecessary details and makes content more concise.
The following example activates the AI-powered “Shorten” extension in a TextEdit control:
<dx:ThemedWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
xmlns:dxai="http://schemas.devexpress.com/winfx/2008/xaml/ai"
x:Class="AIAssistant.MainWindow"
Title="MainWindow" Height="800" Width="800">
<Grid>
<dxe:TextEdit TextWrapping="Wrap" AcceptsReturn="True" VerticalContentAlignment="Top">
<dxmvvm:Interaction.Behaviors>
<dxai:ShortenBehavior x:Name="Shorten"/>
</dxmvvm:Interaction.Behaviors>
</dxe:TextEdit>
</Grid>
</dx:ThemedWindow>
Summarize
SummarizeBehavior generates a brief summary of long text.
SummarizeBehavior
supports the following summarization modes:
Abstractive Summarization
Generates a summary by understanding the context of the original text and rephrasing it in a new, concise form. The AI essentially “writes” a new summary based on its understanding, which may include new sentences that were not present in the original text.
Extractive Summarization
Selects and extracts key sentences or phrases from the original text. The AI identifies the most important parts of the content and combines them into a summary without altering the original wording.
The following example activates the AI-powered “Summarize” extension in a TextEdit control:
<dx:ThemedWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
xmlns:dxai="http://schemas.devexpress.com/winfx/2008/xaml/ai"
x:Class="AIAssistant.MainWindow"
Title="MainWindow" Height="800" Width="800">
<Grid>
<dxe:TextEdit TextWrapping="Wrap" AcceptsReturn="True" VerticalContentAlignment="Top">
<dxmvvm:Interaction.Behaviors>
<dxai:SummarizeBehavior x:Name="Summarize" SummarizationMode = "Extractive"/>
</dxmvvm:Interaction.Behaviors>
</dxe:TextEdit>
</Grid>
</dx:ThemedWindow>
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 example activates the AI-powered “Translate” extension in a TextEdit control:
<dx:ThemedWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
xmlns:dxai="http://schemas.devexpress.com/winfx/2008/xaml/ai"
x:Class="AIAssistant.MainWindow"
Title="MainWindow" Height="800" Width="800">
<Grid>
<dxe:TextEdit TextWrapping="Wrap" AcceptsReturn="True" VerticalContentAlignment="Top">
<dxmvvm:Interaction.Behaviors>
<dxai:TranslateBehavior x:Name="Translate">
<dxai:LanguageInfo Culture="de-DE"/>
<dxai:LanguageInfo Culture="es-ES"/>
</dxai:TranslateBehavior>
</dxmvvm:Interaction.Behaviors>
</dxe:TextEdit>
</Grid>
</dx:ThemedWindow>
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, and the AI assistant will process the query and generate an answer.
The user can 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.
The following example activates the AI-powered “Ask” extension in a TextEdit control:
<dx:ThemedWindow
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:dxe="http://schemas.devexpress.com/winfx/2008/xaml/editors"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm"
xmlns:dxai="http://schemas.devexpress.com/winfx/2008/xaml/ai"
x:Class="AIAssistant.MainWindow"
Title="MainWindow" Height="800" Width="800">
<Grid>
<dxe:TextEdit TextWrapping="Wrap" AcceptsReturn="True" VerticalContentAlignment="Top">
<dxmvvm:Interaction.Behaviors>
<dxai:CustomRequestBehavior x:Name="CustomRequest"/>
</dxmvvm:Interaction.Behaviors>
</dxe:TextEdit>
</Grid>
</dx:ThemedWindow>
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.
To process chunks one by one, the user can click 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 at once. The chunk length is limited to 6,000 symbols. The TextBufferMaxSize property specifies the maximum size of the input text, in bytes.