我对计时器和 AutocompleteBox 工具包有疑问。我有带有 TextChanged 事件的 AutoCompletebox。在此事件中,我启动计时器以使过滤更顺畅(当用户写入时,过滤器不起作用)。当我写的时候一切正常,但是当我从下拉列表中选择 TextChanged 事件时,我没有计时器 Tick 事件(过滤器不启动)。我做错了什么?
xml:
<Controls:AutoCompleteBox Name="acbIdentyfikatorPcS" ValueMemberPath="Identyfikator" FilterMode="Contains" HorizontalAlignment="Left" Margin="100,5,0,0" Grid.Row="1" VerticalAlignment="Top" Width="121" ToolTip="Identyfikator" MinimumPrefixLength="0" TextChanged="acbSerwisant_TextChanged" IsTextCompletionEnabled="True">
<Controls:AutoCompleteBox.ItemTemplate>
<DataTemplate>
<TextBlock Margin="0,0,10,0" FontWeight="Bold" Text="{Binding Identyfikator}"></TextBlock>
</DataTemplate>
</Controls:AutoCompleteBox.ItemTemplate>
</Controls:AutoCompleteBox>
CS:声明:
private DispatcherTimer timerfiltr = new DispatcherTimer();
private DataTable PcS;
public MainWindow()
{
InitializeComponent();
timerfiltr.Tick += new EventHandler(timerfiltr_Tick);
timerfiltr.Interval = new TimeSpan(0, 0, 0, 0, 400);
}
private void acbSerwisant_TextChanged(object sender, RoutedEventArgs e)
{
timerfiltr.Stop();
timerfiltr.IsEnabled = true;
timerfiltr.Start();
}
private void timerfiltr_Tick(object sender, EventArgs e)
{
PcS.DefaultView.RowFilter = "Identyfikator like '%" + acbIdentyfikatorPcS.Text + "%'";
timerfiltr.Stop();
timerfiltr.IsEnabled = false;
}
编辑:
我想我发现了我的问题:这个 AutoCompleteBox 在 TabItem 之一上,我也有 TabControl SelectionChanged 事件,其中还有 timer.stop() 命令
private void TabControl_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
//rest of code
// timerfiltr.Stop();
}
当我按下键盘上的键(AutoCompleteBox 聚焦)时,DropDown 打开,然后 TabControl SelectionChanged 事件也启动和停止计时器......奇怪