Skip to content

Instantly share code, notes, and snippets.

@juucustodio
Created December 15, 2017 13:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save juucustodio/5f0fca96480f460fe22a454e05c75b3c to your computer and use it in GitHub Desktop.
Save juucustodio/5f0fca96480f460fe22a454e05c75b3c to your computer and use it in GitHub Desktop.
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