public ChatWindow(GwupeClientAppContext appContext, EngagementWindow engagementWindow) { this.InitializeComponent(); _appContext = appContext; _engagementWindow = engagementWindow; Chat = _engagementWindow.Engagement.Functions["Chat"] as Function; Chat.NewActivity += ChatOnNewMessage; ChatPanelViewer.ScrollToBottom(); DataContext = new ChatWindowDataContext(_appContext, this); // need to do this here, because we get weird errors if its part of the data context. ChatPanel.ItemsSource = new DispatchingCollection <ObservableCollection <IChatMessage>, IChatMessage>(Chat.Conversation.Exchange, Dispatcher); }
private void ChatOnNewMessage(object sender, EngagementActivity e) { if (!Dispatcher.CheckAccess()) // Only run with dispatcher { Dispatcher.Invoke(new Action(() => ChatOnNewMessage(sender, e))); return; } // Only run event handler if the dispatcher is not shutting down. if (!Dispatcher.HasShutdownStarted) { ChatPanelViewer.ScrollToBottom(); if (_lastMessage.Day != DateTime.Now.Day) { Logger.Debug("Rolling over into new day, adjusting times in " + _engagementWindow.Engagement.SecondParty.Party.Username); // This is to make sure that all the items 'friendly dates' remain correct on midnight rollover ChatPanel.Items.Refresh(); } _lastMessage = DateTime.Now; } }