嘗試使用Text
屬性是這樣的:
XAML
<ComboBox Name="MyComboBox" IsEditable="True" IsTextSearchEnabled="True" SelectedIndex="0" Width="150" Height="30">
<ComboBoxItem>3</ComboBoxItem>
<ComboBoxItem>2</ComboBoxItem>
<ComboBoxItem>4</ComboBoxItem>
<ComboBoxItem>6</ComboBoxItem>
</ComboBox>
<Button Width="100" Height="30" Content="GetEditedText" VerticalAlignment="Bottom" Click="Button_Click" />
Code behind
private void Button_Click(object sender, RoutedEventArgs e)
{
MessageBox.Show(MyComboBox.Text.ToString());
}
或者通過模板到TextBox
訪問:
private void Button_Click(object sender, RoutedEventArgs e)
{
TextBox input = ((TextBox)MyComboBox.Template.FindName("PART_EditableTextBox", MyComboBox));
MessageBox.Show(input.Text.ToString());
}
winforms或WPF?標記它。 –
其WPF應用程序 – freakmoder
也就是說,您需要在ComboBox中使用當前文本? –