删除时未触发WPF文本框textChanged事件

时间:2015-03-25 22:03:09

标签: c# wpf xaml visual-studio-2013

我正在开发一个Visual Studio插件项目。我在WPF窗口中发现了一个非常奇怪的文本框问题。

如果在Visual Studio中没有打开代码文件,则在文本框中输入和删除都可以。但是当在Visual Studio中打开代码文件时,我只能键入文本框。按"退格"即使文本框具有焦点,也会删除代码文件中的文本。按"退格键"时,不会触发textChanged事件

XAML:

<TextBox Name="textBoxSearch" 
DockPanel.Dock="Right" Margin="10" Width="400" BorderThickness="0" 
TextChanged="textBoxSearch_TextChanged" Focusable="True" />

C#:

private string reportPath = null;
private IEnumerable<CaiasResult> resultCollection;
CollectionView resultCollectionView;

public resultWindow(IEnumerable<CaiasResult> resultCollection, string reportPath)
{
    InitializeComponent();
    this.reportPath = reportPath;
    //this.DataContext = this;
    this.resultCollection= resultCollection;
    listViewResults.ItemsSource = resultCollection;
    CollectionView resultView = (CollectionView)CollectionViewSource.GetDefaultView(listViewResults.ItemsSource);
    resultView.Filter = ResultFilter;
}

private bool ResultFilter(object item)
{
    if (string.IsNullOrEmpty(textBoxSearch.Text))
        return true;
    else
        return ((item as CaiasResult).info.IndexOf(textBoxSearch.Text, StringComparison.OrdinalIgnoreCase) >= 0);
}

private void textBoxSearch_TextChanged(object sender, System.Windows.Controls.TextChangedEventArgs e)
{
    CollectionViewSource.GetDefaultView(listViewResults.ItemsSource).Refresh();

}

1 个答案:

答案 0 :(得分:0)

尝试使用此活动: PreviewKeyDown