finally client

This commit is contained in:
KP9lKk 2025-03-14 15:34:03 +03:00
parent 2a68bf0630
commit cd3ee5cb4b
14 changed files with 37 additions and 3 deletions

View File

@ -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<string> 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);

View File

@ -14,7 +14,23 @@
to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
<vm:MainWindowViewModel/>
</Design.DataContext>
<DockPanel>
<StackPanel DockPanel.Dock="Bottom"
Spacing="15"
Orientation="Horizontal"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<TextBox
Text="{Binding CurrentMessage}"
Width="300"
HorizontalContentAlignment="Center"/>
<Button
Command="{Binding SendMessage}"
CommandParameter="{Binding CurrentMessage}"
Width="100"
Content="Send Message"
HorizontalContentAlignment="Center"/>
</StackPanel>
<ListBox ItemsSource="{Binding Messages}">
<ListBox.ItemTemplate>
<DataTemplate>
@ -22,4 +38,6 @@
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</DockPanel>
</Window>

View File

@ -13,7 +13,7 @@ using System.Reflection;
[assembly: System.Reflection.AssemblyCompanyAttribute("AvaloniaChatV2")]
[assembly: System.Reflection.AssemblyConfigurationAttribute("Debug")]
[assembly: System.Reflection.AssemblyFileVersionAttribute("1.0.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0")]
[assembly: System.Reflection.AssemblyInformationalVersionAttribute("1.0.0+2a68bf06307b8fb47c7538d3e5ae2e9a5b974032")]
[assembly: System.Reflection.AssemblyProductAttribute("AvaloniaChatV2")]
[assembly: System.Reflection.AssemblyTitleAttribute("AvaloniaChatV2")]
[assembly: System.Reflection.AssemblyVersionAttribute("1.0.0.0")]

View File

@ -1 +1 @@
7f04708fb6fc5a345bbcf485de564bc617392498b408e5501bff3f5eb31dd3aa
74ae42220328a85f4d8a0cf41ccaa19b8a97ce9b9b94e2667d04a231bcb7e7c7