我有組合框是這樣的:獲取選定項的標籤在WPF組合框
<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>
如何在代碼獲取標記值?
寫一些像ExpireAfterTimeComboBox.SelectedItem.Tag
不起作用。
不要迂腐或任何東西,但爲什麼不只是聲明selectedTag爲一個字符串,如果你正在調用Object.ToString()方法? – djdanlib 2011-06-10 16:52:34
@djdanlib - 沒有特別的理由。當我開始輸入答案時,我使用了'var',然後在記住'Tag'返回一個對象而不是字符串後放置'ToString'。 – keyboardP 2011-06-10 16:56:19