Skip to content
Introducing AI Conversations: Natural Language Interaction for Your Apps! Learn More

ChatView | Getting Started

Add the NuGet package:

Terminal window
dotnet add package Shiny.Maui.Controls

Register in MauiProgram.cs:

builder.UseShinyControls();

Add the XML namespace to your page:

xmlns:shiny="http://shiny.com/controls"

Add the NuGet package:

Terminal window
dotnet add package Shiny.Blazor.Controls

Add the using directive to _Imports.razor or your component:

@using Shiny.Blazor.Controls.Chat

A minimal working chat with send capability:

ChatPage.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:shiny="http://shiny.com/controls"
x:Class="MyApp.ChatPage">
<shiny:ChatView Messages="{Binding Messages}"
SendCommand="{Binding SendCommand}" />
</ContentPage>

ChatViewModel.cs:

public partial class ChatViewModel : ObservableObject
{
[ObservableProperty]
ObservableCollection<ChatMessage> messages = new()
{
new ChatMessage
{
Text = "Hey! How can I help you today?",
SenderId = "bot",
IsFromMe = false,
Timestamp = DateTimeOffset.Now.AddMinutes(-2)
}
};
[RelayCommand]
void Send(string text)
{
Messages.Add(new ChatMessage
{
Text = text,
SenderId = "me",
IsFromMe = true,
Timestamp = DateTimeOffset.Now
});
}
}

That’s it — you have a working chat with bubbles, timestamps, and Enter-to-send.

@page "/chat"
@using Shiny.Blazor.Controls.Chat
<div style="height: 100vh;">
<ChatView Messages="messages"
SendCommand="OnSend" />
</div>
@code {
List<ChatMessage> messages = new()
{
new ChatMessage
{
Text = "Hey! How can I help you today?",
SenderId = "bot",
IsFromMe = false,
Timestamp = DateTimeOffset.Now.AddMinutes(-2)
}
};
Task OnSend(string text)
{
messages.Add(new ChatMessage
{
Text = text,
SenderId = "me",
IsFromMe = true,
Timestamp = DateTimeOffset.Now
});
StateHasChanged();
return Task.CompletedTask;
}
}

Simulate an AI or bot responding after your message:

[RelayCommand]
async Task Send(string text)
{
// Add user message
Messages.Add(new ChatMessage
{
Text = text,
SenderId = "me",
IsFromMe = true,
Timestamp = DateTimeOffset.Now
});
// Simulate bot thinking
await Task.Delay(1500);
// Add bot reply
Messages.Add(new ChatMessage
{
Text = "Thanks for your message! Let me look into that.",
SenderId = "bot",
IsFromMe = false,
Timestamp = DateTimeOffset.Now
});
}
<shiny:ChatView Messages="{Binding Messages}"
SendCommand="{Binding SendCommand}"
ChatBackgroundColor="#F0F0F0"
MyBubbleColor="#007AFF"
MyTextColor="White"
OtherBubbleColor="#E5E5EA"
OtherTextColor="Black"
BubbleFontSize="16"
BubbleFontFamily="OpenSans-Regular"
TimestampFontSize="10"
BubbleCornerRadius="12"
PlaceholderText="Ask me anything..."
SendButtonText="Go"
SendButtonBackgroundColor="#34C759"
SendButtonTextColor="White"
InputBarBackgroundColor="#FAFAFA"
InputBarBorderColor="#CCCCCC" />

Now that you have a working chat, explore: