The way you can access the ComboBoxItem
to check if the Name
matches, is by using the ItemContainerGenerator
of the ComboBox
:
private void DropdownMenuNachten_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var selectedItemContainer = AantalPersonenCombobox.ItemContainerGenerator.ContainerFromIndex(AantalPersonenCombobox.SelectedIndex) as ComboBoxItem;
if (selectedItemContainer?.Name == "tweePersonen")
{
MessageBox.Show("Your Cheap");
}
}
However, if you don't expect the ComboBoxItem
content to change then it would be better to check for the content itself: AantalPersonenCombobox.SelectedItem == "2 Personen"
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…