void InvokeAddTab(ChatUser friend, string message) { if (FindMatchingChatControl(friend.Summary.SteamId) != null) return; if (!chatTabs.Dispatcher.CheckAccess()) chatTabs.Dispatcher.Invoke(() => { var tabItem = new TabItem { Header = friend.Summary.PersonaName }; var chatControl = new ChatControl(this, tabItem, ChatHandler, friend); tabItem.Content = chatControl; chatTabs.Items.Add(tabItem); if (!string.IsNullOrEmpty(message)) InvokeHandleMessage(chatControl, message); chatTabs.SelectedIndex = chatTabs.Items.Count - 1; }); else { var tabItem = new TabItem { Header = friend.Summary.PersonaName }; var chatControl = new ChatControl(this, tabItem, ChatHandler, friend); tabItem.Content = chatControl; chatTabs.Items.Add(tabItem); if (!string.IsNullOrEmpty(message)) InvokeHandleMessage(chatControl, message); chatTabs.SelectedIndex = chatTabs.Items.Count - 1; } }
void OnChatMessage(object sender, ChatMessageArgs e) { ChatControl control = FindMatchingChatControl(IdConversions.AccountIdToUlong(e.ChatMessage.AccountIdFrom)); if (control == null) { return; } InvokeHandleMessage(control, e.ChatMessage.Text); }
void InvokeHandleMessage(ChatControl control, string message) { if (!control.Dispatcher.CheckAccess()) { control.Dispatcher.Invoke(() => { control.HandleMessage(message); }); } else { control.HandleMessage(message); } }
void InvokeAddTab(ChatUser friend, string message) { if (FindMatchingChatControl(friend.Summary.SteamId) != null) { return; } if (!chatTabs.Dispatcher.CheckAccess()) { chatTabs.Dispatcher.Invoke(() => { var tabItem = new TabItem { Header = friend.Summary.PersonaName }; var chatControl = new ChatControl(this, tabItem, ChatHandler, friend); tabItem.Content = chatControl; chatTabs.Items.Add(tabItem); if (!string.IsNullOrEmpty(message)) { InvokeHandleMessage(chatControl, message); } chatTabs.SelectedIndex = chatTabs.Items.Count - 1; }); } else { var tabItem = new TabItem { Header = friend.Summary.PersonaName }; var chatControl = new ChatControl(this, tabItem, ChatHandler, friend); tabItem.Content = chatControl; chatTabs.Items.Add(tabItem); if (!string.IsNullOrEmpty(message)) { InvokeHandleMessage(chatControl, message); } chatTabs.SelectedIndex = chatTabs.Items.Count - 1; } }
void InvokeHandleMessage(ChatControl control, string message) { if (!control.Dispatcher.CheckAccess()) control.Dispatcher.Invoke(() => { control.HandleMessage(message); }); else control.HandleMessage(message); }