C# 获取.NET 4中可编辑组合框的当前文本

C# 获取.NET 4中可编辑组合框的当前文本,c#,wpf,binding,combobox,C#,Wpf,Binding,Combobox,在.NET 3.5中,我有一个实现,它获取组合框的当前编辑文本,如下所示: dependencyObject.GetValue(ComboBox.TextProperty); 一切正常,值为ComboBox.text-Property上编辑的文本。现在我们升级到.NET4,返回值是旧文本,而不是第一个奇怪的行为——编辑文本。但是,如果ComboBox的上一个值是ComboBox.ItemsSource中的项,则上面的代码将返回编辑后的值。目前,我不知道微软在.NET4中对该属性做了什么更改。有

在.NET 3.5中,我有一个实现,它获取组合框的当前编辑文本,如下所示:

dependencyObject.GetValue(ComboBox.TextProperty);

一切正常,值为ComboBox.text-Property上编辑的文本。现在我们升级到.NET4,返回值是旧文本,而不是第一个奇怪的行为——编辑文本。但是,如果ComboBox的上一个值是ComboBox.ItemsSource中的项,则上面的代码将返回编辑后的值。目前,我不知道微软在.NET4中对该属性做了什么更改。有人知道现在会有什么不同吗?

尝试使用
Text
这样的属性:

dependencyObject.GetValue(ComboBox.TextProperty);
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" />
或通过模板访问
文本框

private void Button_Click(object sender, RoutedEventArgs e)
{       
    TextBox input = ((TextBox)MyComboBox.Template.FindName("PART_EditableTextBox", MyComboBox));

    MessageBox.Show(input.Text.ToString()); 
}

尝试使用
Text
属性,如下所示:

dependencyObject.GetValue(ComboBox.TextProperty);
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" />
或通过模板访问
文本框

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应用程序。也就是说,您需要在
组合框中获取当前文本。我需要来自可编辑组合框的当前编辑文本。winforms或WPF?标记它。这是一个WPF应用程序。也就是说,您需要在
组合框中获取当前文本。我需要“可编辑”组合框中当前编辑的文本。