I have combobox like this:
<ComboBox Name="ExpireAfterTimeComboBox" Margin="5" SelectedIndex="0">
<ComboBoxItem Content="15 minutes" Tag="15" />
<ComboBoxItem Content="30 minutes" Tag="30" />
<ComboBoxItem Content="1 hour" Tag="60" />
<ComboBoxItem Content="1 day" Tag="1440" />
</ComboBox>
How do I get Tag value in code?
writing something like ExpireAfterTimeComboBox.SelectedItem.Tag
doesn't work.
When you select an item, it will be displayed on the textbox. We recommend that you execute the above example code and try some other properties and events of the combobox control.
You can display the selected value from combobox to textbox by using the SelectedValuePath and SelectedValue property of WPF ComboBoxAdv control.
You need to cast it to a type of ComboBoxItem
.
var selectedTag = ((ComboBoxItem)ExpireAfterTimeComboBox.SelectedItem).Tag.ToString();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With