Articles in this section
Category / Section

How to restrict the automatic submission of suggestions in .NET MAUI Chat(SfChat)?

3 mins read

In .NET MAUI Chat, when a Suggestion is clicked or selected, the message is automatically sent. This guide explains how to prevent the automatic submission by handling the SendMessage event.

To restrict automatic submission, handle the SendMessage event in the XAML configuration.

<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
             xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
             xmlns:local="clr-namespace:ChatMaui"
             xmlns:sfchat="clr-namespace:Syncfusion.Maui.Chat;assembly=Syncfusion.Maui.Chat"
             x:Class="ChatMaui.MainPage">
    
    <ContentPage.BindingContext>
        <local:GettingStartedViewModel/>
    </ContentPage.BindingContext>

    <ContentPage.Content>
    <sfchat:SfChat x:Name="sfChat" 
                       SendMessage="sfChat_SendMessage"
                       SuggestionItemSelected="sfChat_SuggestionItemSelected"
                       Messages="{Binding Messages}" 
                       CurrentUser="{Binding CurrentUser}">
        </sfchat:SfChat>
    </ContentPage.Content>
</ContentPage>
public partial class MainPage : ContentPage
{
   object selectedItem;
   
    public MainPage()
    {
        InitializeComponent();
    }

    private void sfChat_SendMessage(object sender, SendMessageEventArgs e)
    {
        if (selectedItem  != null) 
        {
            e.Handled = true;
            selectedItem = null;
        }
    }

    private void sfChat_SuggestionItemSelected(object sender, SuggestionItemSelectedEventArgs e)
    {
        selectedItem = e.SelectedItem;
    }
  }

Download the complete sample on GitHub.

Conclusion

I hope you enjoyed learning how to restrict the automatic submission of suggestions in .NET MAUI Chat.

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

Check out our components from the License and Downloads page for current customers. 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 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