From cd3ee5cb4b41fb119b62f7dbfc51af46cb59e6b9 Mon Sep 17 00:00:00 2001 From: KP9lKk Date: Fri, 14 Mar 2025 15:34:03 +0300 Subject: [PATCH] finally client --- .../ViewModels/MainWindowViewModel.cs | 16 ++++++++++++++ AvaloniaChatV2/Views/MainWindow.axaml | 20 +++++++++++++++++- .../bin/Debug/net8.0/AvaloniaChatV2.dll | Bin 201728 -> 205824 bytes .../bin/Debug/net8.0/AvaloniaChatV2.pdb | Bin 14624 -> 15076 bytes .../Debug/net8.0/Avalonia/AvaloniaChatV2.dll | Bin 201728 -> 205824 bytes .../Debug/net8.0/Avalonia/AvaloniaChatV2.pdb | Bin 14624 -> 15076 bytes .../obj/Debug/net8.0/Avalonia/resources | Bin 178345 -> 179032 bytes .../net8.0/AvaloniaChatV2.AssemblyInfo.cs | 2 +- .../AvaloniaChatV2.AssemblyInfoInputs.cache | 2 +- .../obj/Debug/net8.0/AvaloniaChatV2.dll | Bin 189440 -> 192000 bytes .../obj/Debug/net8.0/AvaloniaChatV2.pdb | Bin 14400 -> 14740 bytes .../obj/Debug/net8.0/ref/AvaloniaChatV2.dll | Bin 7168 -> 8192 bytes .../net8.0/refint/Avalonia/AvaloniaChatV2.dll | Bin 7168 -> 8192 bytes .../Debug/net8.0/refint/AvaloniaChatV2.dll | Bin 8192 -> 8704 bytes 14 files changed, 37 insertions(+), 3 deletions(-) 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) --> - + + + +