Пример #1
0
        public void ReceiveUserDisconnectedFromChatNotification(string username)
        {
            lock (_monitor)
            {
                Dispatcher.Invoke(() =>
                {
                    var usernameText  = new TextRange(RichTextBoxMainChatWindow.Document.ContentEnd, RichTextBoxMainChatWindow.Document.ContentEnd);
                    usernameText.Text = username;
                    usernameText.ApplyPropertyValue(TextElement.ForegroundProperty, (ListBoxUsers.ItemsSource as List <UserView>).Where(x => x.Name == username).First().Color);

                    var content  = new TextRange(RichTextBoxMainChatWindow.Document.ContentEnd, RichTextBoxMainChatWindow.Document.ContentEnd);
                    content.Text = " disconnected";
                    content.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.DimGray);

                    RichTextBoxMainChatWindow.AppendText(Environment.NewLine);
                    RichTextBoxMainChatWindow.ScrollToEnd();

                    (ListBoxUsers.ItemsSource as List <UserView>).RemoveAll(x => x.Name == username);
                    ListBoxUsers.Items.Refresh();
                });
            }
        }
Пример #2
0
        public void ReceiveIncomingChatMessage(ChatMessage message)
        {
            lock (_monitor)
            {
                Dispatcher.Invoke(() =>
                {
                    var username  = new TextRange(RichTextBoxMainChatWindow.Document.ContentEnd, RichTextBoxMainChatWindow.Document.ContentEnd);
                    username.Text = message.Username;
                    username.ApplyPropertyValue(TextElement.ForegroundProperty, (ListBoxUsers.ItemsSource as List <UserView>).Where(x => x.Name == message.Username).First().Color);

                    var date  = new TextRange(RichTextBoxMainChatWindow.Document.ContentEnd, RichTextBoxMainChatWindow.Document.ContentEnd);
                    date.Text = "  " + DateTime.Now.ToString("[HH:mm]") + ": ";
                    date.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.Gray);

                    var content  = new TextRange(RichTextBoxMainChatWindow.Document.ContentEnd, RichTextBoxMainChatWindow.Document.ContentEnd);
                    content.Text = message.Content;
                    content.ApplyPropertyValue(TextElement.ForegroundProperty, Brushes.DimGray);

                    RichTextBoxMainChatWindow.AppendText(Environment.NewLine);
                    RichTextBoxMainChatWindow.ScrollToEnd();
                });
            }
        }