private void ContactListBoxSelectionChanged(object sender, SelectionChangedEventArgs e) { ComboBox comboBox = sender as ComboBox; AddressBookWindow myAddressBookWindow = TryFindParent <AddressBookWindow>(comboBox); Grid contactInfoGrid = myAddressBookWindow.Address_book_grid; int index = 0; if (comboBox != null && comboBox.SelectedItem != null) { foreach (Contact contact in _addressBook.Entries) { if (contact.Name == comboBox.SelectedItem.ToString()) { index = _addressBook.Entries.IndexOf(contact); } } foreach (TextBox textBox in contactInfoGrid.Children.OfType <TextBox>()) { Binding myBinding = new Binding(textBox.Tag.ToString()) { Source = _addressBook.Entries[index] }; textBox.SetBinding(TextBox.TextProperty, myBinding); } } }
private void RemoveContactClick(object sender, RoutedEventArgs e) { AddressBookWindow myAddressBookWindow = TryFindParent <AddressBookWindow>(sender as Button); ComboBox comboBox = myAddressBookWindow.Address_book_combobox; int index = 0; foreach (Contact contact in _addressBook.Entries) { if (contact.Name == comboBox.SelectedItem.ToString()) { index = _addressBook.Entries.IndexOf(contact); } } _addressBook.Entries.RemoveAt(index); comboBox.Items.Refresh(); }