MVVM for SfChat

Does the SfChat control require specific properties for Messages?

In my MVVM, I do have the ObservableCollection<MessageModel> messages property to handle messages but the properties of the MessageModel are different than what's in the getting started documentation. Do they need to match e.g. Author, Text, etc?

Currently when I run the code, I'm getting a System.InvalidCastException: 'Object must implement IConvertible.' error.

Any suggestions?


1 Reply

SV Suja Venkatesan Syncfusion Team May 22, 2022 05:27 AM UTC

Hi Sam,

You can achieve your requirement by implementing the interface IChatMessageConverter. The IChatMessageConverter interface provides the methods ConvertToChatMessage and ConvertToData to convert an item of an existing collection to a chat message and to convert a chat message to an item of the existing data collection respectively. Please refer our user guidelines documentation regarding data binding of SfChat in the below link.

UG link: https://help.syncfusion.com/xamarin/chat/data-binding

We have attached a simple sample for binding properties of custom model to the SfChat control for your reference. Please have a look at this sample and let us know if you need any further assistance.

Regards,

Suja


Attachment: SfChat_customBinidng_337c877c.zip

Loader.
Up arrow icon