Prompt to Expression
- 4 minutes to read
Prompt to Expression converts natural language into valid filter and column expressions for data-aware WPF controls. Users describe the desired behavior using their natural language instead of writing complex expressions:
- Sample Filter Expression
- Display delayed shipments
- Sample Column Expression
- Display total cost
The system sends the prompt to the configured AI service that generates a valid expression for the control. The Expression Editor or Filter Editor displays and validates the result immediately.
Supported Controls
- GridControl (Expression Editor and Filter Editor)
- TreeListControl (Expression Editor and Filter Editor)
- ExpressionEditorControl (standalone Expression Editor)
- FilterEditorControl (standalone Filter Editor)
Note
- Prompt to Expression works at runtime only.
- Legacy Expression and Filter Editors are not supported.
Use AI-powered Expressions
Filter Editor
Opens the Filter Editor.

Input intent in the Prompt to Expression field using natural language and click Send.

AI generates a filter expression. The Filter Editor displays the result.

Expression Editor
Open the Expression Editor for an unbound column.

Input an intent in the Prompt to Expression field using a natural language and click Send.

AI generates the expression. The Expression Editor displays the result.

Activate Prompt to Expression
Prerequisites
.NET 8 SDK / .NET Framework v4.7.2
Install DevExpress NuGet Packages
DevExpress.AIIntegration.WpfDevExpress.Mvvm.UIDevExpress.Mvvm.UI.Interactivity
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 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";
// For example, ModelId = "gpt-4o-mini"
IChatClient azureChatClient = new Azure.AI.OpenAI.AzureOpenAIClient(new Uri(AzureOpenAIEndpoint),
new System.ClientModel.ApiKeyCredential(AzureOpenAIKey)).GetChatClient(ModelId).AsIChatClient();
AIExtensionsContainerDesktop.Default.RegisterChatClient(azureChatClient);
}
}
}
Attach Prompt to Expression Behavior
Attach PromptToExpressionBehavior to a supported control in XAML or in code.
XAML
<ThemedWindow xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:dxg="http://schemas.devexpress.com/winfx/2008/xaml/grid"
xmlns:dxai="http://schemas.devexpress.com/winfx/2008/xaml/ai"
xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm">
<dxg:GridControl ItemsSource="{Binding Employees}">
<dxmvvm:Interaction.Behaviors>
<dxai:PromptToExpressionBehavior
RetryAttemptCount="3"
Temperature="0.3"
AugmentWithFunctionInfo="True" />
</dxmvvm:Interaction.Behaviors>
<dxg:GridControl.View>
<dxg:TableView />
</dxg:GridControl.View>
</dxg:GridControl>
</ThemedWindow>
Code-Behind
using DevExpress.AIIntegration.Wpf;
using DevExpress.Mvvm.UI.Interactivity;
var behavior = new PromptToExpressionBehavior {
RetryAttemptCount = 3,
Temperature = 0.3f,
AugmentWithFunctionInfo = true
};
Interaction.GetBehaviors(gridControl).Add(behavior);
Behavior Properties
- RetryAttemptCount
- Gets or sets the number of subsequent attempts to generate a valid expression using the AI service after the initial failure. This is a dependency property.
- Temperature
- Gets or sets the balance between creativity and consistency in AI responses. This is a dependency property.
- PromptAugmentation
- Gets or sets additional instructions that modify the prompt before processing. This is a dependency property.
- AugmentWithFunctionInfo
- Gets or sets whether to inject information about supported functions and operators into each user prompt. This is a dependency property.
- EnableInExpressionEditor
- Gets or sets whether to display the AI prompt control in the Expression Editor. This is a dependency property.
- EnableInFilterEditor
- Gets or sets whether to display the AI prompt control in the Filter Editor. This is a dependency property.
Keyboard Navigation
Use the following keystrokes to interact with the Prompt to Expression interface:
Key | Action |
|---|---|
Enter | Moves the caret to the next line. |
Ctrl + Enter | Sends a prompt to the AI service. |
Esc | Cancels a request. |
Specific Notes
- Runtime Scope
- Design-time Filter Editor and Expression Editor are not supported.
- Retry Policy
- Use RetryAttemptCount to specify the number of subsequent attempts to generate an expression after the initial failure.
- Error Handling
- Expression Editor and Filter Editor validate generated expressions and display an error message when all attempts to generate a valid expression failed.