Articles in this section
Category / Section

How to intercept the message created in .NET MAUI Chat (SfChat)?

2 mins read

The .NET MAUI Chat allows to handle the message in SendMessage event or SendMessageCommand. Programmatically add the actual sent message into the Messages collection before adding the new message created in the event.

XAML

<sfChat:SfChat x:Name="sfChat"
               Messages="{Binding Messages}"
               SendMessageCommand="{Binding SendMessageCommand}"
               CurrentUser="{Binding CurrentUser}" />

ViewModel

public class GettingStartedViewModel : INotifyPropertyChanged
{    
    public ICommand SendMessageCommand { get; set; }
    
    public GettingStartedViewModel()
    {       
        SendMessageCommand = new Command(ExecuteSendMessageCommand);
    }

    private void ExecuteSendMessageCommand(object obj)
    {
        // Skips adding new message in Messages collection.
        var eventArgs = obj as Syncfusion.Maui.Chat.SendMessageEventArgs;
        eventArgs!.Handled = true;

        // Retrieve message using SendMessageEventArgs.Message.
        // Now add the actual sent message into collection as required.
        var message = eventArgs.Message;
        if (message != null) { this.Messages.Add(message); }

        // You can add the special message into collection as like below.
        TextMessage textMessage = new TextMessage() { Author = this.CurrentUser };
        textMessage.Text = "Special Message";
        this.Messages.Add(textMessage);
    }
}

Download the complete sample from GitHub

Conclusion:

I hope you enjoyed learning how to intercept the message created in .NET MAUI Chat (SfChat).

You can refer to our .NET MAUI SfChat feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started with configuration specifications.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion®, try our 30-day free trial to check out our other controls.

Please let us know in the comments section below if you have any queries or require clarification. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Please  to leave a comment
Access denied
Access denied