Skip to main content
You are viewing help content for pre-release software. This document and the features it describes are subject to change.
All docs
V26.1
  • Generate Expressions from Prompts (WPF Report Designer)

    • 4 minutes to read

    Prompt to Expression converts natural language into valid expressions. Instead of writing complex expressions, users describe the desired logic in plain text.

    The system sends the prompt to the configured AI service, which generates a valid expression. The Expression Editor or Filter Editor displays the result immediately. If Prompt to Expression fails to create a valid expression, it displays a message that informs the user that a valid expression was not generated.

    Prompt to Expression - WPF Expression and Filter Editors, DevExpress Reports

    Run Demo: Prompt to Expression

    How It Works

    Expression Editor

    1. The user opens the Expression Editor, enters a prompt in the Prompt to Expression field, and clicks Send.

      Prompt to Expression - WPF Expression Editor, DevExpress Reports

    2. AI generates the expression and the Expression Editor displays the result.

      Prompt to Expression Result - WPF Expression Editor, DevExpress Reports

    Filter Editor

    1. The user opens the Filter Editor, enters a prompt in the Prompt to Expression field, and clicks Send.

      Prompt to Expression - WPF Filter Editor, DevExpress Reports

    2. AI generates a filter expression and the Filter Editor displays the result.

      Prompt to Expression Result - WPF Filter Editor, DevExpress Reports

    Activate Prompt to Expression

    Prerequisites

    • .NET 8+ SDK / .NET Framework v4.7.2
    • Visual Studio 2022+

    Install NuGet Packages

    This help topic uses Azure OpenAI. See the following help topic for information about NuGet packages required for other supported AI services: AI-powered Extensions.

    Note

    DevExpress AI-powered extensions follow the “bring your own key” principle. DevExpress does not offer a REST API and does not ship any built-in LLMs/SLMs. You need an active Azure/Open AI subscription to obtain the REST API endpoint, key, and model deployment name. These variables must be specified at application startup to register AI clients and enable DevExpress AI-powered Extensions in your application.

    Register AI Client

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

    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-5.2.
        [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());
        }
    }
    

    Create and Configure Behavior Object

    Attach the ReportPromptToExpressionBehavior to the Report Designer to enable AI-powered Prompt-to-Report functionality.

    The following properties are available:

    ReportPromptToExpressionBehavior.RetryAttemptCount
    Specifies the number of additional attempts the AI makes to regenerate an expression if the previous result is invalid.
    ReportPromptToExpressionBehavior.PromptAugmentation
    Appends additional instructions to each user prompt.
    ReportPromptToExpressionBehavior.Temperature
    Specifies creativity in AI responses. Set 1 for models (for example, GPT-5, o1, and o3 series) that ignore this parameter to avoid compatibility errors. The default value is 0.

    Markup

    The following code snippet creates a ReportPromptToExpressionBehavior and configures its Temperature and RetryAttemptCount settings:

    <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:dxrud="http://schemas.devexpress.com/winfx/2008/xaml/reports/userdesigner"
        xmlns:dxmvvm="http://schemas.devexpress.com/winfx/2008/xaml/mvvm" 
        xmlns:dxai="http://schemas.devexpress.com/winfx/2008/xaml/ai"
        x:Class="DXWPFReportApp.MainWindow"
        Title="Report Designer" Height="800" Width="1000">
        <Grid>
            <dxrud:ReportDesigner x:Name="reportDesigner" Height="NaN" Width="NaN">
                <dxmvvm:Interaction.Behaviors>
                    <dxai:ReportPromptToExpressionBehavior x:Name="promptToExpressionBehavior" RetryAttemptCount="3" Temperature="1"/>
                </dxmvvm:Interaction.Behaviors>
            </dxrud:ReportDesigner>
        </Grid>
    </dx:ThemedWindow>
    

    Runtime

    The following code snippet registers a ReportPromptToExpressionBehavior and attaches it to the WPF Report Designer (reportDesigner):

    using DevExpress.Xpf.Core;
    using DevExpress.Mvvm.UI.Interactivity;
    using DevExpress.AIIntegration.Wpf.Reporting;
    
    namespace WPFReportApp {
        public partial class MainWindow : ThemedWindow {
            public MainWindow() {
                InitializeComponent();
                var promptToExpressionBehavior = new ReportPromptToExpressionBehavior() {
                    RetryAttemptCount = 3,
                    Temperature = 1
                };
                var behaviors = Interaction.GetBehaviors(reportDesigner);
                behaviors.Add(promptToExpressionBehavior);
                reportDesigner.OpenDocument(new Report1());
            }
        }
    }