Xamarin Forms 中用于 SfChat 控件的 MVVM

MVVM for SfChat Control in Xamarin Forms

Xamarin Forms 的 SfChat 控件是否需要 Messages 的特定属性?

在我的模型中,我确实有 ObservableCollection<MessageModel> messages 属性 来处理消息,但是我的 MessageModel 的属性与 getting started documentation 中的不同。他们需要匹配吗? AuthorText 等?例如,在我的模型中,属性 没有命名为 Author,而是命名为 Sender。另一个是 Text 属性。在我的模型中,它被命名为 Body.

当前,当我 运行 代码时,出现以下错误:

System.InvalidCastException: 'Object must implement IConvertible.'

我确实认识到如果我没有将我的模型的属性正确绑定到控件就会抛出这个错误。关于如何将我的模型的属性正确绑定到控件的任何建议,或者我是否需要确保 属性 名称正是控件所期望的?

docs 似乎涵盖了这个

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.

您需要提供一个 IChatMessageConverter 来将您的 class 与 SF 数据格式相互转换