public void RecieveMessage(ChatMessage msg) { // create the paragraph Paragraph p = new Paragraph(); Run rnMyText = new Run(); p.FontWeight = FontWeights.Bold; // if the message is from the currently logged in user, then set the color to gray if (msg.From == _chatRoomWindow.Username) { p.Foreground = new SolidColorBrush(Colors.Gray); rnMyText.Text = string.Format("{0} (me): {1}", msg.From, msg.MessageText); } else { p.Foreground = new SolidColorBrush(Colors.Green); rnMyText.Text = string.Format("{0}: {1}", msg.From, msg.MessageText); } // add the text to the paragraph tag p.Inlines.Add(rnMyText); // add the paragraph to the rich text box _chatRoomWindow.rtbChatLog.Document.Blocks.Add(p); }
/// <summary> /// Handle Chat Message button click /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void btnSendChat_Click(object sender, RoutedEventArgs e) { //// create the chat message var chatMessageBody = new ChatMessage() { From = Username, MessageText = txtUserChatMessage.Text }; var messageBody = new SocketServiceMessage() { Action = SocketServiceAction.ChatMessage, Message = chatMessageBody }; var msg = JsonMessageSerializer.Serialize(messageBody); ////send the message to the service topic _svcClient.Receive(msg); }
/// <summary> /// Handle the user clicking the send button /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private async void btnSendChatMessage_Click(object sender, RoutedEventArgs e) { // create the chat message and send it across the wire var chatMessage = new ChatMessage() { From = _username, MessageText = txtUserMessage.Text }; // create the wrapper message and serialize it to string var wrapperMsg = new SocketServiceMessage() { Action = SocketServiceAction.ChatMessage, Message = chatMessage }; string msg = JsonConvert.SerializeObject(wrapperMsg); // buffer the message messageWriter.WriteString(msg); // send the message await messageWriter.StoreAsync(); //_svcClient.SendMessageAsync(msg); // clear out the message text box txtUserMessage.Text = ""; }