private void Button_Click_5(object sender, RoutedEventArgs e)
        {
            UserControlMessageReceived userControlMessageReceived = new UserControlMessageReceived();
            MessageEvent @event = new MessageEvent("Delete", "chat", selectedId, DateTime.Now, 3030, "");

            ConnectToServer.SendRequest(@event);
        }
 public void senderMessage(List <userMessages> mess, bool totalFlag)
 {
     if (mess.Count > 1)
     {
         for (int i = 0; i < mess.Count; i++)
         {
             if (mess[i].senderId == userId)
             {
                 Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                 {
                     UserControlMessageSent userControlMessageSent = new UserControlMessageSent();
                     userControlMessageSent.changeText(mess[i].content);
                     userControlMessageSent.Id = mess[i].messageId;
                     userControlMessageSent.HorizontalAlignment = HorizontalAlignment.Right;
                     userControlMessageSent.timeSent.Text       = mess[i].createAt.ToString();
                     messagePlace.Children.Add(userControlMessageSent);
                     scrollViewerMess.ScrollToBottom();
                     messageTextBox.Focus();
                 }));
             }
             else
             {
                 Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                 {
                     UserControlMessageReceived userControlMessageReceived = new UserControlMessageReceived();
                     userControlMessageReceived.timeRec.Text     = mess[i].createAt.ToString();
                     userControlMessageReceived.messageText.Text = mess[i].content;
                     userControlMessageReceived.Id = mess[i].messageId;
                     userControlMessageReceived.HorizontalAlignment = HorizontalAlignment.Left;
                     messagePlace.Children.Add(userControlMessageReceived);
                     scrollViewerMess.ScrollToBottom();
                     messageTextBox.Focus();
                 }));
             }
         }
     }
     else
     {
         if (totalFlag)
         {
             if (mess[0].recipientGroupId == Convert.ToInt32(selectedId))
             {
                 Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                 {
                     UserControlMessageReceived userControlMessageReceived = new UserControlMessageReceived();
                     userControlMessageReceived.timeRec.Text     = mess[0].createAt.ToString();
                     userControlMessageReceived.messageText.Text = mess[0].content;
                     userControlMessageReceived.Id = mess[0].messageId;
                     userControlMessageReceived.HorizontalAlignment = HorizontalAlignment.Left;
                     messagePlace.Children.Add(userControlMessageReceived);
                     scrollViewerMess.ScrollToBottom();
                     messageTextBox.Focus();
                 }));
             }
             else
             {
                 Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                 {
                     foreach (ListViewItem lvi in this.listViewI)
                     {
                         if (lvi.Name == $"id{mess[0].recipientGroupId}")
                         {
                             ListViewItem listViewItem = (ListViewItem)listViewI[listViewI.IndexOf(lvi)];
                             if ((bool)listViewItem.Tag)
                             {
                                 Border border     = (Border)listViewItem.FindName("messageBorderCount");
                                 TextBlock block   = (TextBlock)listViewItem.FindName("messageCount");
                                 border.Visibility = Visibility.Visible;
                                 block.Text        = Convert.ToString(Convert.ToInt32(block.Text) + 1);
                                 messageTextBox.Focus();
                             }
                         }
                     }
                 }));
             }
         }
         else
         {
             if (mess[0].recipientChatId == Convert.ToInt32(selectedId))
             {
                 Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                 {
                     UserControlMessageReceived userControlMessageReceived = new UserControlMessageReceived();
                     userControlMessageReceived.timeRec.Text     = mess[0].createAt.ToString();
                     userControlMessageReceived.messageText.Text = mess[0].content;
                     userControlMessageReceived.Id = mess[0].messageId;
                     userControlMessageReceived.HorizontalAlignment = HorizontalAlignment.Left;
                     messagePlace.Children.Add(userControlMessageReceived);
                     messageTextBox.Focus();
                     scrollViewerMess.ScrollToBottom();
                 }));
             }
             else
             {
                 Dispatcher.Invoke(DispatcherPriority.Background, new Action(() =>
                 {
                     foreach (ListViewItem lvi in this.listViewI)
                     {
                         if (lvi.Name == $"id{mess[0].recipientChatId}")
                         {
                             ListViewItem listViewItem = (ListViewItem)listViewI[listViewI.IndexOf(lvi)];
                             if (!(bool)listViewItem.Tag)
                             {
                                 Border border     = (Border)listViewItem.FindName("messageBorderCount");
                                 TextBlock block   = (TextBlock)listViewItem.FindName("messageCount");
                                 border.Visibility = Visibility.Visible;
                                 block.Text        = Convert.ToString(Convert.ToInt32(block.Text) + 1);
                                 messageTextBox.Focus();
                             }
                         }
                     }
                 }));
             }
         }
     }
 }