private void ChatMessage_OnEdit(Controls.ChatMessage sender, Message args) { this.CurrentState = ContextualMessageOperation.Edit; ContextType.Text = "Edit:"; ContextMessage.Text = args.RawMessage; MessageContextGrid.Visibility = Visibility.Visible; MessageInput.Text = args.RawMessage; ContextMessageData = args; MessageInput.Focus(FocusState.Programmatic); SetFocusToInput(); }
private async void Connect(object sender, RoutedEventArgs args) { if (_connection == null) { ConnectButton.IsEnabled = false; ConnectButton.Content = "Connecting"; var client = new TcpClient(); try { await client.ConnectAsync(IpInput.Text, int.Parse(PortInput.Text)); } catch (Exception error) { ConnectButton.IsEnabled = true; ConnectButton.Content = "Connect"; DisplayMessage(new ChatMessage { Username = "******", Content = $"Unable to connect to host. Reason: {error.Message}", Sender = ChatSender.Internal }); return; } DisplayMessage(new ChatMessage { Username = "******", Content = $"Connected to {client.Client.RemoteEndPoint}.", Sender = ChatSender.Internal }); _userId = Guid.NewGuid(); _connection = new TcpConnection(client); _connection.OnMessageReceived += ReceiveMessage; _connection.OnConnectionLost += ConnectionLost; UsernameInput.IsEnabled = false; IpInput.IsEnabled = false; PortInput.IsEnabled = false; ConnectButton.IsEnabled = true; ConnectButton.IsDefault = false; ConnectButton.IsCancel = true; ConnectButton.Content = "Disconnect"; MessageInput.IsEnabled = true; SendButton.IsEnabled = true; SendButton.IsDefault = true; MessageInput.Focus(); } else { _connection.Dispose(); _connection = null; UsernameInput.IsEnabled = true; IpInput.IsEnabled = true; PortInput.IsEnabled = true; ConnectButton.IsDefault = true; ConnectButton.IsCancel = false; ConnectButton.Content = "Connect"; MessageInput.IsEnabled = false; SendButton.IsEnabled = false; SendButton.IsDefault = false; } }
private void SetFocusToInput() { MessageInput.Focus(FocusState.Programmatic); MessageInput.Select(MessageInput.Text.Length, 0); }