using Avalonia; using Avalonia.Controls; using Avalonia.LogicalTree; using Avalonia.Markup.Xaml; using Avalonia.VisualTree; using ReactiveUI; using Remotely.Desktop.Linux.ViewModels; using System; using System.Linq; using System.Threading.Tasks; namespace Remotely.Desktop.Linux.Views { public class ChatWindow : Window { public ChatWindow() { InitializeComponent(); #if DEBUG this.AttachDevTools(); #endif } private ChatWindowViewModel ViewModel => DataContext as ChatWindowViewModel; private void ChatWindow_Closed(object sender, System.EventArgs e) { Environment.Exit(0); } private async void ChatWindow_KeyUp(object sender, Avalonia.Input.KeyEventArgs e) { if (e.Key == Avalonia.Input.Key.Enter) { await ViewModel.SendChatMessage(); } } private void InitializeComponent() { AvaloniaXamlLoader.Load(this); Closed += ChatWindow_Closed; this.FindControl("TitleBanner").PointerPressed += TitleBanner_PointerPressed; this.FindControl("InputTextBox").KeyUp += ChatWindow_KeyUp; this.FindControl("MessagesListBox").ItemContainerGenerator.Materialized += ItemContainerGenerator_Materialized; } private async void ItemContainerGenerator_Materialized(object sender, Avalonia.Controls.Generators.ItemContainerEventArgs e) { // Allows listbox height to adjust to content before scrolling the scrollviewer. await Task.Delay(1); // TODO: Replace with ScrollToEnd when implemented. var scrollViewer = this.FindControl("MessagesScrollViewer"); var listBox = this.FindControl("MessagesListBox"); scrollViewer.Offset = new Vector(0, listBox.Bounds.Height); } private void TitleBanner_PointerPressed(object sender, Avalonia.Input.PointerPressedEventArgs e) { if (e.GetCurrentPoint(this).Properties.PointerUpdateKind == Avalonia.Input.PointerUpdateKind.LeftButtonPressed) { BeginMoveDrag(e); } } } }