RadzenChat Class

A chat interface component for displaying and sending messages in multi-participant conversations. RadzenChat provides a complete chat UI with message history, user avatars, typing indicators, and message composition. Creates a messaging interface similar to modern chat applications, ideal for customer support chats, team collaboration, messaging features, or AI chatbots. Features multi-user support displaying messages from multiple participants with avatars and names, chronological message list with sender identification, user avatars showing photos or initials with customizable colors, optional "User is typing..." feedback, text input with Send button for new messages, customizable templates for message rendering/empty state/typing indicator, automatic scrolling to newest messages, and message send time stamps. Provide a list of ChatUser objects for participants and ChatMessage objects for message history. Set CurrentUserId to distinguish the current user's messages (typically right-aligned) from others (left-aligned). Handle MessageSent to process new messages (save to database, send to server, etc.).

Inheritance

Object

ComponentBase

RadzenComponent

RadzenChat

Implements

IComponent

IHandleEvent

IHandleAfterRender

Namespace: Radzen.Blazor

Assembly: Radzen.Blazor.dll

Syntax

public class RadzenChat : RadzenComponent, IComponent, IHandleEvent, IHandleAfterRender

Examples

Basic chat:

<RadzenChat CurrentUserId=@currentUserId Users=@users Messages=@messages MessageSent=@OnMessageSent />
@code {
    string currentUserId = "user1";
    List<ChatUser> users = new() { new ChatUser { Id = "user1", Name = "John" }, new ChatUser { Id = "user2", Name = "Jane" } };
    List<ChatMessage> messages = new();

    async Task OnMessageSent(ChatMessage message)
    {
        messages.Add(message);
        await SaveMessage(message);
    }
}

Constructors

RadzenChatlink

A chat interface component for displaying and sending messages in multi-participant conversations. RadzenChat provides a complete chat UI with message history, user avatars, typing indicators, and message composition. Creates a messaging interface similar to modern chat applications, ideal for customer support chats, team collaboration, messaging features, or AI chatbots. Features multi-user support displaying messages from multiple participants with avatars and names, chronological message list with sender identification, user avatars showing photos or initials with customizable colors, optional "User is typing..." feedback, text input with Send button for new messages, customizable templates for message rendering/empty state/typing indicator, automatic scrolling to newest messages, and message send time stamps. Provide a list of ChatUser objects for participants and ChatMessage objects for message history. Set CurrentUserId to distinguish the current user's messages (typically right-aligned) from others (left-aligned). Handle MessageSent to process new messages (save to database, send to server, etc.).

Declaration
public RadzenChat()

Properties

ChatClearedlink

Event callback that is invoked when the chat is cleared.

Declaration
public EventCallback ChatCleared { get; set; }
Property Value
Type Description
EventCallbackEvent callback that is invoked when the chat is cleared.

CurrentUserIdlink

Gets or sets the current user's participant ID.

Declaration
public string CurrentUserId { get; set; }
Property Value
Type Description
stringGets or sets the current user's participant ID.

Disabledlink

Gets or sets whether the chat is disabled.

Declaration
public bool Disabled { get; set; }
Property Value
Type Description
boolGets or sets whether the chat is disabled.

EmptyMessagelink

Gets or sets the message displayed when there are no messages.

Declaration
public string EmptyMessage { get; set; }
Property Value
Type Description
stringGets or sets the message displayed when there are no messages.

EmptyTemplatelink

Gets or sets the empty template shown when there are no messages.

Declaration
public RenderFragment EmptyTemplate { get; set; }
Property Value
Type Description
RenderFragmentGets or sets the empty template shown when there are no messages.

InputAttributeslink

Specifies additional custom attributes that will be rendered by the input.

Declaration
public IReadOnlyDictionary<string, object> InputAttributes { get; set; }
Property Value
Type Description
IReadOnlyDictionary<string, object>Specifies additional custom attributes that will be rendered by the input.

MaxMessageslink

Gets or sets the maximum number of messages to keep in the chat.

Declaration
public int MaxMessages { get; set; }
Property Value
Type Description
intGets or sets the maximum number of messages to keep in the chat.

MaxVisibleUserslink

Gets or sets the maximum number of users to show in the header.

Declaration
public int MaxVisibleUsers { get; set; }
Property Value
Type Description
intGets or sets the maximum number of users to show in the header.

MessageAddedlink

Event callback that is invoked when a new message is added.

Declaration
public EventCallback<ChatMessage> MessageAdded { get; set; }
Property Value
Type Description
EventCallback<ChatMessage>Event callback that is invoked when a new message is added.

MessageSentlink

Event callback that is invoked when a message is sent.

Declaration
public EventCallback<ChatMessage> MessageSent { get; set; }
Property Value
Type Description
EventCallback<ChatMessage>Event callback that is invoked when a message is sent.

MessageTemplatelink

Gets or sets the message template.

Declaration
public RenderFragment<ChatMessage> MessageTemplate { get; set; }
Property Value
Type Description
RenderFragment<ChatMessage>Gets or sets the message template.

Messageslink

Gets or sets the list of chat messages.

Declaration
public IEnumerable<ChatMessage> Messages { get; set; }
Property Value
Type Description
IEnumerable<ChatMessage>Gets or sets the list of chat messages.

MessagesChangedlink

Event callback that is invoked when the messages list changes.

Declaration
public EventCallback<IEnumerable<ChatMessage>> MessagesChanged { get; set; }
Property Value
Type Description
EventCallback<IEnumerable<ChatMessage>>Event callback that is invoked when the messages list changes.

MultipleUsersTypingFormatlink

Gets or sets the multiple users typing format. TypingTemplate has preference over this property.

Declaration
public string MultipleUsersTypingFormat { get; set; }
Property Value
Type Description
stringGets or sets the multiple users typing format. TypingTemplate has preference over this property.

NewMessagesTextlink

Gets or sets the text displayed on the new messages indicator button.

Declaration
public string NewMessagesText { get; set; }
Property Value
Type Description
stringGets or sets the text displayed on the new messages indicator button.

Placeholderlink

Gets or sets the placeholder text for the input field.

Declaration
public string Placeholder { get; set; }
Property Value
Type Description
stringGets or sets the placeholder text for the input field.

ReadOnlylink

Gets or sets whether the input is read-only.

Declaration
public bool ReadOnly { get; set; }
Property Value
Type Description
boolGets or sets whether the input is read-only.

ShowClearButtonlink

Gets or sets whether to show the clear chat button.

Declaration
public bool ShowClearButton { get; set; }
Property Value
Type Description
boolGets or sets whether to show the clear chat button.

ShowTypingIndicatorlink

Gets or sets whether to show a typing indicator in the message list.

Declaration
public bool ShowTypingIndicator { get; set; }
Property Value
Type Description
boolGets or sets whether to show a typing indicator in the message list.

ShowUserNameslink

Gets or sets whether to show participant names above messages.

Declaration
public bool ShowUserNames { get; set; }
Property Value
Type Description
boolGets or sets whether to show participant names above messages.

ShowUserslink

Gets or sets whether to show users in the header.

Declaration
public bool ShowUsers { get; set; }
Property Value
Type Description
boolGets or sets whether to show users in the header.

Titlelink

Gets or sets the title displayed in the chat header.

Declaration
public string Title { get; set; }
Property Value
Type Description
stringGets or sets the title displayed in the chat header.

TwoUsersTypingFormatlink

Gets or sets the two users typing format. TypingTemplate has preference over this property.

Declaration
public string TwoUsersTypingFormat { get; set; }
Property Value
Type Description
stringGets or sets the two users typing format. TypingTemplate has preference over this property.

TypingChangedlink

Raised when the current user's typing state changes (true/false). Use this to broadcast typing state via SignalR etc.

Declaration
public EventCallback<ChatTypingEventArgs> TypingChanged { get; set; }
Property Value
Type Description
EventCallback<ChatTypingEventArgs>Raised when the current user's typing state changes (true/false). Use this to broadcast typing state via SignalR etc.

TypingFormatlink

Gets or sets the single user typing format. TypingTemplate has preference over this property.

Declaration
public string TypingFormat { get; set; }
Property Value
Type Description
stringGets or sets the single user typing format. TypingTemplate has preference over this property.

TypingTemplatelink

Optional template to render typing indicator content. Receives the typing ChatUser list (excluding current user by default).

Declaration
public RenderFragment<IReadOnlyList<ChatUser>> TypingTemplate { get; set; }
Property Value
Type Description
RenderFragment<IReadOnlyList<ChatUser>>Optional template to render typing indicator content. Receives the typing ChatUser list (excluding current user by default).

TypingTimeoutlink

Gets or sets the debounce timeout (in milliseconds) after the last keystroke before the current user is considered "not typing".

Declaration
public int TypingTimeout { get; set; }
Property Value
Type Description
intGets or sets the debounce timeout (in milliseconds) after the last keystroke before the current user is considered "not typing".

UserAddedlink

Event callback that is invoked when a participant is added.

Declaration
public EventCallback<ChatUser> UserAdded { get; set; }
Property Value
Type Description
EventCallback<ChatUser>Event callback that is invoked when a participant is added.

UserRemovedlink

Event callback that is invoked when a participant is removed.

Declaration
public EventCallback<ChatUser> UserRemoved { get; set; }
Property Value
Type Description
EventCallback<ChatUser>Event callback that is invoked when a participant is removed.

Userslink

Gets or sets the list of chat users.

Declaration
public IEnumerable<ChatUser> Users { get; set; }
Property Value
Type Description
IEnumerable<ChatUser>Gets or sets the list of chat users.

UsersChangedlink

Event callback that is invoked when the users list changes.

Declaration
public EventCallback<IEnumerable<ChatUser>> UsersChanged { get; set; }
Property Value
Type Description
EventCallback<IEnumerable<ChatUser>>Event callback that is invoked when the users list changes.

Methods

AddMessagelink

Adds a message to the chat.

Declaration
public Task<ChatMessage> AddMessage(string content, string userId)
Parameters
Type Name Description
string content The message content.
string userId The ID of the participant who sent the message.
Returns
Type Description
Task<ChatMessage>The created message.

AddUserlink

Adds a participant to the chat.

Declaration
public Task AddUser(ChatUser participant)
Parameters
Type Name Description
ChatUser participant The participant to add.
Returns
Type Description
Task

BuildRenderTreelink

Declaration
protected override void BuildRenderTree(Rendering.RenderTreeBuilder __builder)
Parameters
Type Name Description
Rendering.RenderTreeBuilder __builder

ClearChatlink

Clears all messages from the chat.

Declaration
public Task ClearChat()
Returns
Type Description
Task

Disposelink

Declaration
public override void Dispose()

GetComponentCssClasslink

Declaration
protected override string GetComponentCssClass()
Returns
Type Description
string

GetMessageslink

Gets the current list of messages.

Declaration
public IReadOnlyList<ChatMessage> GetMessages()
Returns
Type Description
IReadOnlyList<ChatMessage>

GetUserlink

Gets the current list of users.

Declaration
public ChatUser GetUser(string userId)
Parameters
Type Name Description
string userId
Returns
Type Description
ChatUser

GetUserslink

Gets the current list of users.

Declaration
public IReadOnlyList<ChatUser> GetUsers()
Returns
Type Description
IReadOnlyList<ChatUser>

LoadMessageslink

Loads messages from an external source.

Declaration
public Task LoadMessages(IEnumerable<ChatMessage> messages)
Parameters
Type Name Description
IEnumerable<ChatMessage> messages The messages to load.
Returns
Type Description
Task

OnAfterRenderAsynclink

Declaration
protected override Task OnAfterRenderAsync(bool firstRender)
Parameters
Type Name Description
bool firstRender
Returns
Type Description
Task

RemoveUserlink

Removes a participant from the chat.

Declaration
public Task RemoveUser(string userId)
Parameters
Type Name Description
string userId The ID of the participant to remove.
Returns
Type Description
Task

ScrollToBottomlink

Scrolls to the bottom of the message list and dismisses the new messages indicator.

Declaration
public Task ScrollToBottom()
Returns
Type Description
Task

SendMessagelink

Sends a message programmatically.

Declaration
public Task SendMessage(string content, string userId)
Parameters
Type Name Description
string content The message content to send.
string userId The ID of the participant sending the message (defaults to CurrentUserId).
Returns
Type Description
Task

SetUserTypinglink

Sets a participant typing state. Use this for remote users (e.g. SignalR updates).

Declaration
public Task SetUserTyping(string userId, bool isTyping)
Parameters
Type Name Description
string userId
bool isTyping
Returns
Type Description
Task

UpdateUserStatuslink

Updates a participant's online status.

Declaration
public Task UpdateUserStatus(string userId, bool isOnline)
Parameters
Type Name Description
string userId The participant ID.
bool isOnline The online status.
Returns
Type Description
Task
An error has occurred. This app may no longer respond until reloaded. Reload 🗙