Exemple #1
0
        private void AddMessage(string v)
        {
            ListBoxItem item = new ListBoxItem()
            {
                MaxWidth = 250
            };
            string     user    = v.Substring(0, v.IndexOf(':'));
            string     message = v.Substring(v.IndexOf(':') + 1);
            StackPanel stack   = new StackPanel();
            Border     border  = new Border()
            {
                CornerRadius = new CornerRadius(5)
            };

            border.SetResourceReference(Control.BackgroundProperty, "ElementsColor");
            border.Child = new TextBlock()
            {
                TextWrapping = TextWrapping.Wrap, Margin = new Thickness(5), Text = message
            };
            TextBlock tbMetaData = new TextBlock()
            {
                TextWrapping = TextWrapping.Wrap, HorizontalAlignment = user == UserName ? HorizontalAlignment.Right : HorizontalAlignment.Left, Margin = new Thickness(0, 5, 0, 5), Text = $"{DateTime.Now.ToShortTimeString()} {user}"
            };

            stack.Children.Add(border);
            stack.Children.Add(tbMetaData);
            item.Content             = stack;
            item.HorizontalAlignment = user == UserName ? HorizontalAlignment.Right : HorizontalAlignment.Left;
            MessagesListBox.Items.Add(item);
            MessagesListBox.ScrollIntoView(item);
        }
Exemple #2
0
        private void AddToMessages(ChatMessage chatMessage)
        {
            _messages.Add(chatMessage);
            MessageBox.Text = string.Empty;

            var response = Client.PostMessage(chatMessage);

            _messages.Add(response);

            int lastMessageIndex = MessagesListBox.Items.Count - 1;

            MessagesListBox.ScrollIntoView(MessagesListBox.Items[lastMessageIndex]);
        }
 private void ActiveConvoView_CollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
 {
     if (AtBottom())
     {
         scrollViewer?.ScrollToBottom();
     }
     else
     {
         if (loadingPrevMsgs)
         {
             loadingPrevMsgs = false;
             MessagesListBox.ScrollIntoView(lastItem);
         }
     }
 }