Skip to main content
All docs
V26.1
  • AIChatControl.MarkdownConvert Event

    Allows you to convert Markdown-formatted response text to HTML before the AI Chat Control displays it.

    Namespace: DevExpress.AIIntegration.WinForms.Chat

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

    NuGet Package: DevExpress.AIIntegration.WinForms.Chat

    Declaration

    [DXCategory("Events")]
    public event EventHandler<AIChatControlMarkdownConvertEventArgs> MarkdownConvert

    Event Data

    The MarkdownConvert event's data class is DevExpress.AIIntegration.Blazor.Chat.WebView.AIChatControlMarkdownConvertEventArgs.

    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 to HTML and make responses more readable and structured.

    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.

    using DevExpress.AIIntegration.Blazor.Chat;
    using DevExpress.AIIntegration.Blazor.Chat.WebView;
    using Ganss.Xss;
    using Markdig;
    
    HtmlSanitizer sanitizer;
    
    public Chat() {
        InitializeComponent();
        sanitizer = new HtmlSanitizer();
        aiChatControl1.ContentFormat = ResponseContentFormat.Markdown;
        aiChatControl1.MarkdownConvert += AiChatControl1_MarkdownConvert;
    }
    
    void AiChatControl1_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 - WinForms AI Chat Control, DevExpress

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

    The following code snippet (auto-collected from DevExpress Examples) contains a reference to the MarkdownConvert event.

    Note

    The algorithm used to collect these code examples remains a work in progress. Accordingly, the links and snippets below may produce inaccurate results. If you encounter an issue with code examples below, please use the feedback form on this page to report the issue.

    See Also