Class RadzenChat
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.).
Inherited Members
Namespace: Radzen.Blazor
Assembly: Radzen.Blazor.dll
Syntax
public class RadzenChat : RadzenComponent, IComponent, IHandleEvent, IHandleAfterRender, IDisposable
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
RadzenChat()
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()
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);
}
}
Properties
ChatCleared
Event callback that is invoked when the chat is cleared.
Declaration
[Parameter]
public EventCallback ChatCleared { get; set; }
Property Value
| Type | Description |
|---|---|
| EventCallback |
CurrentUserId
Gets or sets the current user's participant ID.
Declaration
[Parameter]
public string CurrentUserId { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
Disabled
Gets or sets whether the chat is disabled.
Declaration
[Parameter]
public bool Disabled { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
EmptyMessage
Gets or sets the message displayed when there are no messages.
Declaration
[Parameter]
public string EmptyMessage { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
EmptyTemplate
Gets or sets the empty template shown when there are no messages.
Declaration
[Parameter]
public RenderFragment EmptyTemplate { get; set; }
Property Value
| Type | Description |
|---|---|
| RenderFragment | The empty template. |
InputAttributes
Specifies additional custom attributes that will be rendered by the input.
Declaration
[Parameter]
public IReadOnlyDictionary<string, object> InputAttributes { get; set; }
Property Value
| Type | Description |
|---|---|
| IReadOnlyDictionary<string, object> | The attributes. |
MaxMessages
Gets or sets the maximum number of messages to keep in the chat.
Declaration
[Parameter]
public int MaxMessages { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
MaxVisibleUsers
Gets or sets the maximum number of users to show in the header.
Declaration
[Parameter]
public int MaxVisibleUsers { get; set; }
Property Value
| Type | Description |
|---|---|
| int |
MessageAdded
Event callback that is invoked when a new message is added.
Declaration
[Parameter]
public EventCallback<ChatMessage> MessageAdded { get; set; }
Property Value
| Type | Description |
|---|---|
| EventCallback<ChatMessage> |
MessageSent
Event callback that is invoked when a message is sent.
Declaration
[Parameter]
public EventCallback<ChatMessage> MessageSent { get; set; }
Property Value
| Type | Description |
|---|---|
| EventCallback<ChatMessage> |
MessageTemplate
Gets or sets the message template.
Declaration
[Parameter]
public RenderFragment<ChatMessage> MessageTemplate { get; set; }
Property Value
| Type | Description |
|---|---|
| RenderFragment<ChatMessage> | The message template. |
Messages
Gets or sets the list of chat messages.
Declaration
[Parameter]
public IEnumerable<ChatMessage> Messages { get; set; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<ChatMessage> |
MessagesChanged
Event callback that is invoked when the messages list changes.
Declaration
[Parameter]
public EventCallback<IEnumerable<ChatMessage>> MessagesChanged { get; set; }
Property Value
| Type | Description |
|---|---|
| EventCallback<IEnumerable<ChatMessage>> |
Placeholder
Gets or sets the placeholder text for the input field.
Declaration
[Parameter]
public string Placeholder { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
ReadOnly
Gets or sets whether the input is read-only.
Declaration
[Parameter]
public bool ReadOnly { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
ShowClearButton
Gets or sets whether to show the clear chat button.
Declaration
[Parameter]
public bool ShowClearButton { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
ShowUserNames
Gets or sets whether to show participant names above messages.
Declaration
[Parameter]
public bool ShowUserNames { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
ShowUsers
Gets or sets whether to show users in the header.
Declaration
[Parameter]
public bool ShowUsers { get; set; }
Property Value
| Type | Description |
|---|---|
| bool |
Title
Gets or sets the title displayed in the chat header.
Declaration
[Parameter]
public string Title { get; set; }
Property Value
| Type | Description |
|---|---|
| string |
UserAdded
Event callback that is invoked when a participant is added.
Declaration
[Parameter]
public EventCallback<ChatUser> UserAdded { get; set; }
Property Value
| Type | Description |
|---|---|
| EventCallback<ChatUser> |
UserRemoved
Event callback that is invoked when a participant is removed.
Declaration
[Parameter]
public EventCallback<ChatUser> UserRemoved { get; set; }
Property Value
| Type | Description |
|---|---|
| EventCallback<ChatUser> |
Users
Gets or sets the list of chat users.
Declaration
[Parameter]
public IEnumerable<ChatUser> Users { get; set; }
Property Value
| Type | Description |
|---|---|
| IEnumerable<ChatUser> |
UsersChanged
Event callback that is invoked when the users list changes.
Declaration
[Parameter]
public EventCallback<IEnumerable<ChatUser>> UsersChanged { get; set; }
Property Value
| Type | Description |
|---|---|
| EventCallback<IEnumerable<ChatUser>> |
Methods
AddMessage(string, string)
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. |
AddUser(ChatUser)
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 |
BuildRenderTree(RenderTreeBuilder)
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
protected override void BuildRenderTree(RenderTreeBuilder __builder)
Parameters
| Type | Name | Description |
|---|---|---|
| RenderTreeBuilder | __builder |
Overrides
ClearChat()
Clears all messages from the chat.
Declaration
public Task ClearChat()
Returns
| Type | Description |
|---|---|
| Task |
GetComponentCssClass()
Gets the component CSS class.
Declaration
protected override string GetComponentCssClass()
Returns
| Type | Description |
|---|---|
| string |
Overrides
GetMessages()
Gets the current list of messages.
Declaration
public IReadOnlyList<ChatMessage> GetMessages()
Returns
| Type | Description |
|---|---|
| IReadOnlyList<ChatMessage> |
GetUser(string)
Gets a participant by their ID.
Declaration
public ChatUser GetUser(string userId)
Parameters
| Type | Name | Description |
|---|---|---|
| string | userId | The participant ID. |
Returns
| Type | Description |
|---|---|
| ChatUser | The participant or null if not found. |
GetUsers()
Gets the current list of users.
Declaration
public IReadOnlyList<ChatUser> GetUsers()
Returns
| Type | Description |
|---|---|
| IReadOnlyList<ChatUser> |
LoadMessages(IEnumerable<ChatMessage>)
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 |
OnAfterRenderAsync(bool)
Called by the Blazor runtime.
Declaration
protected override Task OnAfterRenderAsync(bool firstRender)
Parameters
| Type | Name | Description |
|---|---|---|
| bool | firstRender |
Returns
| Type | Description |
|---|---|
| Task |
Overrides
RemoveUser(string)
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 |
SendMessage(string, string)
Sends a message programmatically.
Declaration
public Task SendMessage(string content, string userId = null)
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 |
UpdateUserStatus(string, bool)
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 |