public void SendToBody(string date, string name, string body, int type)//Вывод сообщений в главное окно чата
 {
     ChatBody.Invoke(new Action(() =>
     {
         ChatBody.SelectionFont = new Font(ChatBody.Font.FontFamily, this.Font.Size, FontStyle.Bold);
         ChatBody.AppendText(date.Remove(0, 11).Remove(5)); ChatBody.AppendText(": ");
         if (type == 1)
         {
             ChatBody.SelectionColor = Color.Red;
         }
         ChatBody.AppendText(name);
         ChatBody.SelectionColor = Color.Black;
         if (type == 1)
         {
             ChatBody.AppendText(": ");
             ChatBody.SelectionFont = new Font(ChatBody.Font.FontFamily, this.Font.Size, FontStyle.Regular);
         }
         else
         {
             ChatBody.AppendText(" ");
         }
         ChatBody.AppendText(body + Environment.NewLine);
         ChatBody.ScrollToCaret();
     }));
 }
 public void SendToBody(string date, string name, string body, int type)//Вывод сообщений в главное окно чата
 {
     ChatBody.Dispatcher.Invoke(new Action(() =>
     {
         ChatBody.AppendText(Environment.NewLine);
         ChatBody.FontWeight = FontWeights.Bold;
         ChatBody.AppendText(date.Remove(0, 11).Remove(5)); ChatBody.AppendText(": ");
         if (type == 1)
         {
             ChatBody.Foreground = new SolidColorBrush(Colors.Red);
         }
         ChatBody.AppendText(name);
         ChatBody.Foreground = new SolidColorBrush(Colors.Black);
         if (type == 0)
         {
             ChatBody.AppendText(": ");
             ChatBody.FontWeight = FontWeights.Regular;
         }
         else
         {
             ChatBody.AppendText(" ");
         }
         ChatBody.AppendText(body);
         ChatBody.ScrollToEnd();
     }));
 }
        static List <string> UsersOnline = new List <string>();//Онлайн пользователи

        public MainWindow(string personName, TcpClient iNclient, NetworkStream iNstream, List <string> inUsersOnline)
        {
            InitializeComponent();
            yourName           = personName;
            client             = iNclient;
            stream             = iNstream;
            this.StartPosition = FormStartPosition.CenterScreen;
            UsersOnline        = inUsersOnline;
            Thread receiveThread = new Thread(new ThreadStart(ReceiveMessage));

            receiveThread.Start();
            ChatBody.AppendText(DateTime.Now.ToShortTimeString() + ": Добро пожаловать в чат!" + Environment.NewLine);
        }
        static ObservableCollection <string> UsersOnline = new ObservableCollection <string>();//Онлайн пользователи

        public MainWindow(string personName, TcpClient iNclient, NetworkStream iNstream, ObservableCollection <string> inUsersOnline)
        {
            InitializeComponent();


            Binding bind = new Binding();

            bind.Source        = UsersOnline;
            Online.ItemsSource = UsersOnline;



            yourName    = personName;
            client      = iNclient;
            stream      = iNstream;
            UsersOnline = inUsersOnline;
            Thread receiveThread = new Thread(new ThreadStart(ReceiveMessage));

            receiveThread.SetApartmentState(ApartmentState.STA);
            receiveThread.Start();
            ChatBody.AppendText(DateTime.Now.ToShortTimeString() + ": Добро пожаловать в чат!" + Environment.NewLine);
        }