How to Add a Chat Interface to WPF Apps with ChatControl

This tutorial installs Xceed Toolkit Plus for WPF, builds an MVVM chat view model in C#, explains how to connect it to the new ChatControl-related classes, and covers tips for streaming replies and threading.

A chat interface in WPF needs more than a ListBox and a TextBox. You also need a message model that updates while replies stream in, a send command, sensible auto-scroll, virtualization and thread-safe collection updates. A dedicated chat control, such as ChatControl in Xceed Toolkit Plus for WPF, handles the presentation layer, so most of your own code lives in the view model; confirm its availability and exact classes in the Toolkit Plus documentation. This tutorial installs the Xceed.Products.Wpf.Toolkit.Full NuGet package and builds an MVVM chat view model in plain C#. It then explains how to bind that view model to ChatControl and covers performance tips, offline licensing and the 45-day free trial.

Users now expect conversation-style UI in desktop software. Support consoles, internal AI assistants and field-service tools all ask for a chat panel next to the data. A chat interface WPF teams can maintain over time, however, takes more work than the mockups suggest.

A convincing chat panel needs message bubbles aligned by sender, timestamps and a multi-line input box. It also needs auto-scroll that leaves alone a user who is reading older messages, plus replies that grow word by word as a language model streams them. Each piece is small on its own. Together, they can take days of templating and edge-case fixes.

This tutorial builds that work around ChatControl in Xceed Toolkit Plus for WPF; the Toolkit Plus documentation at doc.xceed.com is the place to confirm availability and exact class names. First, you write the conversation logic as a plain C# view model. Next, you connect it to the control. As a result, the UI layer stays thin and you can unit-test the chat logic.

Why a chat interface in WPF is harder than it looks

Most teams start with built-in controls. A ListBox with a custom DataTemplate shows the messages, while a TextBox and a Button handle input. That prototype takes an afternoon to build. Problems start once real conversations flow through it.

Common problems with a ListBox-based chat

  • Scroll behavior. ListBox has no "stick to bottom" mode. Developers often call ScrollIntoView on every collection change. That pulls the viewport away from users who scrolled up to reread something.
  • Streaming text. A reply that updates dozens of times per second triggers layout every time. In a long list, that text measurement can stall the UI thread.
  • Threading. Un ObservableCollection<T> raises change notifications on the thread that modifies it. WPF throws a NotSupportedException when a background thread changes a bound collection without synchronization.
  • Sender-specific templates. Aligning your messages right and incoming messages left requires a DataTemplateSelector or a stack of triggers.
  • Keyboard conventions. Users expect Enter to send and Shift+Enter to add a new line. A default TextBox does neither out of the box.

None of these problems is exotic. Still, each one adds code that has nothing to do with your actual product. For that reason, a dedicated chat control pays off quickly.

What ChatControl adds to the WPF Toolkit

The name Extended WPF Toolkit often appears in search results, so the editions are worth separating first. The Extended WPF Toolkit is the community edition, a separate product with its own Repositorio GitHub. In contrast, Xceed Toolkit Plus para WPF is the commercial edition. It ships under a per-developer subscription and includes additional controls. Check the release notes on the product page to confirm which version includes ChatControl.

The ChatControl-related classes target the presentation layer of a conversation. Specifically, they cover showing a list of messages, telling senders apart and accepting new input. Meanwhile, your application keeps ownership of the data and of the logic that produces replies. That split matches MVVM well, because the control binds to a collection you already control.

How this tutorial handles the API

This article keeps Xceed-specific calls out of the code samples on purpose. Class names, properties and template parts can change between releases. The official Xceed documentation is therefore the source of truth for exact ChatControl signatures. All of the C# below uses standard .NET and WPF types, so it compiles on its own and works with any chat surface.

Other WPF suites also include conversational UI components. Telerik UI for WPF, DevExpress WPF and Syncfusion Essential Studio for WPF each offer one. Teams that already standardize on one of those suites will often find a chat component that matches their existing themes. Toolkit Plus suits teams that already use Xceed controls, such as DataGrid for WPF, and want one vendor for their WPF UI.

Step 1: Install the WPF Toolkit package

Start with a WPF project targeting .NET 8 or later. Then add the Xceed.Products.Wpf.Toolkit.Full package from NuGet. The current release of this WPF Toolkit package is v5.2, and its root namespace is Xceed.Wpf.Toolkit.

Instalar vía NuGet

dotnet add package Xceed.Products.Wpf.Toolkit.Full

Next, apply your license key. Toolkit Plus reads the key from code at startup, usually in App.xaml.cs before any window opens. The check runs entirely offline, with no activation server and no phone-home. The Toolkit Plus documentation lists the exact licenser property for your version. During evaluation, you can request a key through the 45-day free trial, which needs no credit card.

Step 2: Build the message model and view model

A chat UI is only as good as the data behind it. Therefore, start with a message class that raises change notifications on Text. Streaming replies depend on this, since the same message object grows as tokens arrive.

ChatMessage.cs

usando System;
using System.ComponentModel;
using System.Runtime.CompilerServices;
 
namespace ChatDemo;
 
public sealed class ChatMessage : INotifyPropertyChanged
{
    private string _text = string.Empty;
 
    public string Author { get; init; } = string.Empty;
    public bool IsFromCurrentUser { get; init; }
    public DateTime Timestamp { get; init; } = DateTime.Now;
 
    public string Text
    {
        get => _text;
        set
        {
            if (_text == value) return;
            _text = value;
            OnPropertyChanged();
        }
    }
 
    public event PropertyChangedEventHandler? PropertyChanged;
 
    private void OnPropertyChanged([CallerMemberName] string? name = null)
        => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}

Add an async send command

The send action calls a remote service, so it needs an async command. The small class below also disables itself while a reply is still streaming. That way, users cannot fire a second prompt mid-answer.

AsyncRelayCommand.cs

usando System;
using System.Threading.Tasks;
using System.Windows.Input;
 
namespace ChatDemo;
 
public sealed class AsyncRelayCommand : ICommand
{
    private readonly Func<Task> _execute;
    private readonly Func<bool> _canExecute;
    private bool _isRunning;
 
    public AsyncRelayCommand(Func<Task> execute, Func<bool> canExecute)
    {
        _execute = execute;
        _canExecute = canExecute;
    }
 
    public event EventHandler? CanExecuteChanged
    {
        add => CommandManager.RequerySuggested += value;
        remove => CommandManager.RequerySuggested -= value;
    }
 
    public bool CanExecute(object? parameter) => !_isRunning && _canExecute();
 
    public async void Execute(object? parameter)
    {
        _isRunning = true;
        CommandManager.InvalidateRequerySuggested();
        try
        {
            await _execute();
        }
        finally
        {
            _isRunning = false;
            CommandManager.InvalidateRequerySuggested();
        }
    }
}

Write the chat view model

The view model owns three things: the message collection, the draft text and the send command. In addition, it holds a stub that streams a fake reply. Later, you replace that stub with your real model or chat service.

ChatViewModel.cs

using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Runtime.CompilerServices;
using System.Threading.Tasks;
using System.Windows.Input;
 
namespace ChatDemo;
 
public sealed class ChatViewModel : INotifyPropertyChanged
{
    private string _draft = string.Empty;
 
    public ChatViewModel()
    {
        SendCommand = new AsyncRelayCommand(SendAsync, () => !string.IsNullOrWhiteSpace(Draft));
    }
 
    public ObservableCollection<ChatMessage> Messages { get; } = new();
 
    public string Draft
    {
        get => _draft;
        set { _draft = value; OnPropertyChanged(); }
    }
 
    public ICommand SendCommand { get; }
 
    private async Task SendAsync()
    {
        string prompt = Draft.Trim();
        Draft = string.Empty;
 
        Messages.Add(new ChatMessage { Author = "You", IsFromCurrentUser = true, Text = prompt });
 
        var reply = new ChatMessage { Author = "Assistant" };
        Messages.Add(reply);
 
        // The await resumes on the UI thread, so updating Text here is safe.
        await foreach (string token in GetReplyTokensAsync(prompt))
        {
            reply.Text += token;
        }
    }
 
    // Replace this stub with a call to your model or chat service.
    private static async IAsyncEnumerable<string> GetReplyTokensAsync(string prompt)
    {
        foreach (string word in $"You said: {prompt}".Split(' '))
        {
            await Task.Delay(80);
            yield return word + " ";
        }
    }
 
    public event PropertyChangedEventHandler? PropertyChanged;
 
    private void OnPropertyChanged([CallerMemberName] string? name = null)
        => PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(name));
}

Notice that SendAsync adds the empty reply before streaming starts. As a result, the UI shows the assistant's message bubble right away, and the text fills in as tokens arrive. This pattern gives users immediate feedback, even when the first token takes a second or two.

Step 3: Connect the view model to ChatControl

First, assign the view model as the window's DataContext. This part is standard WPF and does not depend on any Xceed API.

MainWindow.xaml.cs

using System.Windows;
 
namespace ChatDemo;
 
public partial class MainWindow : Window
{
    public MainWindow()
    {
        InitializeComponent();
        DataContext = new ChatViewModel();
    }
}

Next, open MainWindow.xaml, declare the Toolkit Plus XAML namespace and place the ChatControl in your layout. Then bind the control's message source to Messages. Map sender, text and timestamp to the matching ChatMessage properties. Finally, route message submission to SendCommand. If the control exposes a command property, bind to it directly. If it raises an event instead, forward that event to the command from code-behind or with a behavior.

API Reference

The exact XAML namespace URI, element name and property names appear in the Toolkit Plus API reference on doc.xceed.com. Use those names exactly as documented for your installed version.

A chat panel bound to an MVVM view model, with the assistant reply streaming in.

Performance tips for a chat interface in WPF

A working chat panel is only the first milestone. The tips below keep a chat interface WPF users rely on responsive under real traffic.

Batch streaming updates

Language models can emit tokens faster than the eye can read them. Each change to Text triggers a binding update and a layout pass. Instead of updating per token, buffer tokens and flush roughly every 50 milliseconds. The following loop replaces the await foreach block in SendAsync. It also needs using System.Diagnostics; and using System.Text;.

Buffer streaming tokens

var buffer = new StringBuilder();
var stopwatch = Stopwatch.StartNew();
 
await foreach (string token in GetReplyTokensAsync(prompt))
{
    buffer.Append(token);
    if (stopwatch.ElapsedMilliseconds >= 50)
    {
        reply.Text += buffer.ToString();
        buffer.Clear();
        stopwatch.Restart();
    }
}
 
// Flush whatever remains after the stream ends.
reply.Text += buffer.ToString();

Keep collection changes on the UI thread

The sample above stays safe because each await resumes on the UI thread's synchronization context. However, some SDKs push messages from a background thread through callbacks. In that case, marshal the update with the WPF Dispatcher. Alternatively, register the collection with BindingOperations.EnableCollectionSynchronization and use a shared lock.

Cap the in-memory history

Long-running sessions can accumulate thousands of messages. Even with UI virtualization, every item still costs memory. Therefore, trim the oldest entries once the collection passes a threshold, and persist the full transcript to disk or a database. Similarly, send only a recent window of messages to your model, since context limits apply there too.

Test the view model without the UI

The view model has no reference to ChatControl, so you can unit-test it directly. For example, a test can set Draft, execute SendCommand and assert that Messages contains two entries. Swap the token stub for a fake service, and you can also verify error handling and cancellation.

Plan for offline and regulated deployments

Many chat panels run inside hospitals, banks or factory networks. Xceed licensing fits those environments. The license key lives in code, and there is no online activation, so builds and apps run on air-gapped machines. Xceed components also contain no telemetry and collect no data from end users. Furthermore, redistribution of the Xceed assemblies is royalty-free, with no per-deployment or per-user fees. An active per-developer subscription covers building and shipping; the acuerdo de licencia has the full terms. For code reviews, a Blueprint subscription provides the full C# source.

Try ChatControl in Toolkit Plus

Add a chat panel to your WPF app with a 45-day free trial, no credit card required.

Preguntas frecuentes

What is ChatControl in Xceed Toolkit Plus for WPF?

ChatControl is a conversation-style UI component for Xceed Toolkit Plus for WPF. A chat control like this handles the presentation side, such as message lists and input, while your view model supplies the messages and reply logic. The API reference at doc.xceed.com lists the exact classes and members, and the release notes confirm which version includes it.

Is ChatControl part of the free Extended WPF Toolkit?

The Extended WPF Toolkit community edition is a separate product from Toolkit Plus for WPF. Toolkit Plus is the commercial edition, licensed per developer through a subscription. Check the release notes on the Toolkit Plus product page to confirm which edition and version include ChatControl.

Can I connect a WPF chat interface to an AI model?

Yes. The chat control only displays messages, so any service works behind it. Replace the GetReplyTokensAsync stub with a call to your model's streaming API, then append each chunk to the reply message's Text property.

Does Toolkit Plus need internet access to validate the license?

No. You apply the license key in code, and validation happens offline. Xceed uses no online activation, no phone-home and no remote kill-switch, so apps run on fully air-gapped machines.

How do I stop the chat from jumping while users read older messages?

First, check the ChatControl documentation for built-in scroll behavior. If you need custom logic, track whether the scroll position sits at the bottom. Auto-scroll on new messages only when it does, and show a "new messages" indicator otherwise.

Echa un vistazo a la biblioteca de palabras y PDF de Xceed paquete