Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

MVVM for SfChat Control in Xamarin Forms

Does the SfChat control for Xamarin Forms require specific properties for Messages?

In my model, I do have the ObservableCollection<MessageModel> messages property to handle messages but the properties of my MessageModel are different than what’s in the getting started documentation. Do they need to match e.g. Author, Text, etc? For example, in my model, the property is not named Author but Sender. Another one is Text property. In my model it’s named Body.

Currently when I run the code, I’m getting the following error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

System.InvalidCastException: ‘Object must implement IConvertible.’

I do recognize this error which is thrown if I don’t bind properties of my model to the control correctly. Any suggestions as to how to properly bind properties of my model to the control or do I need to make sure property names are exactly what the control expects?

>Solution :

the docs seem to cover this

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.

you need to provide a IChatMessageConverter that will convert your class to and from the SF data format

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading