diff --git a/AvaloniaChatV2/ViewModels/MainWindowViewModel.cs b/AvaloniaChatV2/ViewModels/MainWindowViewModel.cs index 9472fe7..a5aa431 100644 --- a/AvaloniaChatV2/ViewModels/MainWindowViewModel.cs +++ b/AvaloniaChatV2/ViewModels/MainWindowViewModel.cs @@ -6,18 +6,34 @@ using System.Threading; using System.Threading.Tasks; using AvaloniaChatV2.Data; using AvaloniaChatV2.Views; +using ReactiveUI; namespace AvaloniaChatV2.ViewModels; public class MainWindowViewModel : ViewModelBase { private readonly ClientWebSocketHandler _clientWebSocketHandler = new (); + private string _currentMessage = String.Empty; + + public string CurrentMessage + { + get => _currentMessage; + set => this.RaiseAndSetIfChanged(ref _currentMessage, value); + } + public ObservableCollection Messages { get; set; } = new(); public MainWindowViewModel() { _clientWebSocketHandler.OnReceiveMessage += DisplayMessage; } + public async Task SendMessage(string message) + { + Messages.Add(message); + await _clientWebSocketHandler.SendMessage(message); + CurrentMessage = String.Empty; + } + private void DisplayMessage(string message) { Messages.Add(message); diff --git a/AvaloniaChatV2/Views/MainWindow.axaml b/AvaloniaChatV2/Views/MainWindow.axaml index a9f6cd2..793c5ba 100644 --- a/AvaloniaChatV2/Views/MainWindow.axaml +++ b/AvaloniaChatV2/Views/MainWindow.axaml @@ -14,7 +14,23 @@ to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) --> - + + + +