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(); } }
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(); } }
public void ScrollToLastElement() { try { MessageForUI message = App.ChatPageViewModel.MessagesViewModel.LastOrDefault(); if (message != null) { chatMessages.ScrollIntoView(message); } } catch (Exception ex) { ex.ToString(); } }