private void BAdd_Click(object sender, RoutedEventArgs e) { try { if ((string)((TabItem)PlayListTabs.SelectedItem).Header == "Найденые...") { var listBox = (ListBox)PlayListTabs.SelectedContent; var audio = (Audio)listBox.SelectedItem; VkApi.AddAudio(audio.OwnerID, audio.ID); foreach (TabItem tabItem in PlayListTabs.Items) { if ((string)tabItem.Header == "My music") { var listBox2 = (ListBox)(tabItem).FindName("PlayListBox"); if (listBox2 != null) { listBox2.Items.Insert(0, audio); } } } } } catch (NetworkInformationException) { System.Windows.Forms.MessageBox.Show(@"Ошибка интернет соединения."); } }