Esempio n. 1
0
        public async void UpdateMessages(string fromId, string content)
        {
            try
            {
                await dispatcher.RunAsync(CoreDispatcherPriority.Normal, () =>
                {
                    if (_chatConversations.ContainsKey(fromId) == false)
                    {
                        _chatConversations.Add(fromId, new ObservableCollection <MessageForUI>());
                    }

                    MessageForUI receivedMessage = new MessageForUI()
                    {
                        FromId              = fromId,
                        Content             = content,
                        ChatBubbleDirection = Coding4Fun.Toolkit.Controls.ChatBubbleDirection.UpperLeft,
                        Alignment           = Windows.UI.Xaml.HorizontalAlignment.Left
                    };
                    _chatConversations[fromId].Add(receivedMessage);
                    if (App.ChatPageReference != null)
                    {
                        App.ChatPageReference.ScrollToLastElement();
                        App.ChatPageReference.PlayChatSound();
                    }
                });
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }
Esempio n. 2
0
        public void UpdateMessages(string fromId, string content)
        {
            try
            {
                Deployment.Current.Dispatcher.BeginInvoke(() =>
                {
                    if (_chatConversations.ContainsKey(fromId) == false)
                    {
                        _chatConversations.Add(fromId, new ObservableCollection <MessageForUI>());
                    }

                    var receivedMessage = new MessageForUI
                    {
                        FromId              = fromId,
                        Content             = content,
                        ChatBubbleDirection = ChatBubbleDirection.UpperLeft,
                        Alignment           = HorizontalAlignment.Left
                    };
                    _chatConversations[fromId].Add(receivedMessage);
                    if (App.ChatPageReference != null)
                    {
                        App.ChatPageReference.ScrollToLastElement();
                        App.ChatPageReference.PlayChatSound();
                    }
                });
            }
            catch (Exception ex)
            {
                ex.ToString();
            }
        }
Esempio n. 3
0
 public void ScrollToLastElement()
 {
     try
     {
         MessageForUI message = App.ChatPageViewModel.MessagesViewModel.LastOrDefault();
         if (message != null)
         {
             chatMessages.ScrollIntoView(message);
         }
     }
     catch (Exception ex)
     {
         ex.ToString();
     }
 }