using System; using System.Collections.Generic; using System.Collections.ObjectModel; using Avalonia.Controls; using Avalonia.Controls.Primitives; using Avalonia.Input; using Avalonia.Interactivity; using Chapplication.Models; namespace Chapplication; public partial class MainWindow : Window { private ObservableCollection _messages = new(); public MainWindow() { InitializeComponent(); ChatBox.ItemsSource = _messages; } private void SubmitButton_OnClick(object? sender, RoutedEventArgs e) { SendMessage(); } private void ChatInputBox_OnKeyDown(object? sender, KeyEventArgs e) { if (e.Key == Key.Enter) { SendMessage(); } } private void SendMessage() { if (string.IsNullOrWhiteSpace(ChatInputBox.Text)) { return; } _messages.Add(ChatInputBox.Text); ChatInputBox.Text = string.Empty; ChatInputBox.Focus(); } }