Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Example of Chat in Xamarin.Forms applications - http://julianocustodio.com/chat
using DemoChat.CustomCells;
using DemoChat.Models;
using Xamarin.Forms;
namespace DemoChat
{
public class SelectorDataTemplate : DataTemplateSelector
{
private readonly DataTemplate textInDataTemplate;
private readonly DataTemplate textOutDataTemplate;
protected override DataTemplate OnSelectTemplate(object item, BindableObject container)
{
var messageVm = item as Message;
if (messageVm == null)
return null;
return messageVm.IsTextIn ? this.textInDataTemplate : this.textOutDataTemplate;
}
public SelectorDataTemplate()
{
this.textInDataTemplate = new DataTemplate(typeof(TextInViewCell));
this.textOutDataTemplate = new DataTemplate(typeof(TextOutViewCell));
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment