Skip to content

Instantly share code, notes, and snippets.

@juucustodio
Last active December 15, 2017 15:49
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/33146d79cdcbbd48369449d946902705 to your computer and use it in GitHub Desktop.
Save juucustodio/33146d79cdcbbd48369449d946902705 to your computer and use it in GitHub Desktop.
Example of Chat in Xamarin.Forms applications - http://julianocustodio.com/chat
using System;
using System.Globalization;
using System.Windows.Input;
using DemoChat.Models;
using MvvmHelpers;
using Xamarin.Forms;
namespace DemoChat.ViewModels
{
public class MainPageViewModel : BaseViewModel
{
public ObservableRangeCollection<Message> ListMessages { get; }
public ICommand SendCommand { get; set; }
public MainPageViewModel()
{
ListMessages = new ObservableRangeCollection<Message>();
SendCommand = new Command(() =>
{
if (!String.IsNullOrWhiteSpace(OutText))
{
var message = new Message
{
Text = OutText,
IsTextIn = false,
MessageDateTime = DateTime.Now
};
ListMessages.Add(message);
OutText = "";
}
});
}
public string OutText
{
get { return _outText; }
set { SetProperty(ref _outText, value); }
}
string _outText = string.Empty;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment