Created
June 14, 2018 15:27
-
-
Save rdelrosario/3b2a7007477d4a01c4311615aee6170d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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