Skip to main content
All docs
V26.1
  • AIChatControl.ContentFormat Property

    Gets or sets the format of AI responses (PlainText or Markdown). This is a dependency property.

    Namespace: DevExpress.AIIntegration.Wpf.Chat

    Assembly: DevExpress.AIIntegration.Wpf.Chat.v26.1.dll

    NuGet Package: DevExpress.AIIntegration.Wpf.Chat

    Declaration

    public ResponseContentFormat ContentFormat { get; set; }

    Property Value

    Type Description
    ResponseContentFormat

    A ResponseContentFormat enumeration value that specifies the response format.

    Available values:

    Name Description
    Markdown

    An assistant sends the response as Markdown.

    PlainText

    An assistant sends the response as plain text.

    Remarks

    To enable Markdown message rendering:

    1. Set the ContentFormat property to Markdown to receive responses as Markdown.
    2. Handle the MarkdownConvert event to convert markdown text into HTML and make responses more readable, structured, and visually appealing.

    Warning

    Always sanitize AI-generated content before rendering it in the UI.

    Example

    The following example enables Markdown message rendering. The example uses the Markdig Markdown processing library to convert Markdown text into HTML.

    <dxaichat:AIChatControl
        x:Name="aiChatControl"
        UseStreaming="True"
        ContentFormat="Markdown"
        MarkdownConvert="AiChatControl_MarkdownConvert"
        HorizontalAlignment="Stretch" 
        VerticalAlignment="Stretch" 
        Margin="10">
    </dxaichat:AIChatControl>
    
    using DevExpress.Xpf.Core;
    using DevExpress.AIIntegration.Blazor.Chat.WebView;
    using Microsoft.AspNetCore.Components;
    using Ganss.Xss;
    using Markdig;
    
    namespace DXApplication {
        var sanitizer;
    
        public partial class MainWindow : ThemedWindow {
            public MainWindow() {
                InitializeComponent();
                sanitizer = new HtmlSanitizer();
            }
    
            void AiChatControl_MarkdownConvert(object sender, AIChatControlMarkdownConvertEventArgs e) {
                // Convert Markdown to HTML.
                string html = Markdown.ToHtml(e.MarkdownText);
    
                // WARNING: The AI agent's content may be untrusted. 
                // Developers must sanitize all HTML before rendering to prevent XSS attacks.
                string safeHtml = sanitizer.Sanitize(html);
    
                // Assign sanitized HTML for rendering.
                e.HtmlText = (MarkupString)safeHtml;
            }
        }
    }
    

    The following screenshot demonstrates the result:

    Markdown Message Rendering

    Refer to the following help topic for additional information: AI Chat Control

    See Also