public void AddPage(ChatPage page, bool switchToPage) { var item = new ChatTabItem(page); if (page.Type == ChatPageType.Server) { this.Items.Add(item); this.SubscribeEvents(page.Session); } else { for (int i = this.Items.Count - 1; i >= 0; --i) { if (this.Items[i].Page.Session == page.Session) { this.Items.Insert(i + 1, item); break; } } } if (switchToPage) { var oldItem = tabsChat.SelectedItem as TabItem; if (oldItem != null) { oldItem.IsSelected = false; } item.IsSelected = true; } }