Skip to content

Instantly share code, notes, and snippets.

@rdelrosario
Created June 14, 2018 15:27
Show Gist options
  • Select an option

  • Save rdelrosario/3b2a7007477d4a01c4311615aee6170d to your computer and use it in GitHub Desktop.

Select an option

Save rdelrosario/3b2a7007477d4a01c4311615aee6170d to your computer and use it in GitHub Desktop.
using System;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Windows.Input;
using ChatUIXForms.Models;
using Xamarin.Forms;
namespace ChatUIXForms.ViewModels
{
public class ChatPageViewModel: INotifyPropertyChanged
{
public ObservableCollection<Message> Messages { get; set; } = new ObservableCollection<Message>();
public string TextToSend { get; set; }
public ICommand OnSendCommand { get; set; }
public ChatPageViewModel()
{
Messages.Add(new Message() { Text = "Hi" });
Messages.Add(new Message() { Text = "How are you?"});
OnSendCommand = new Command(() =>
{
if(!string.IsNullOrEmpty(TextToSend)){
Messages.Add(new Message() { Text = TextToSend, User = App.User });
TextToSend = string.Empty;
}
});
}
public event PropertyChangedEventHandler PropertyChanged;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment