110,536
社区成员
发帖
与我相关
我的任务
分享
private void SearchListBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.Key == Key.Down)
{
if (SearchListBox.Items.CurrentPosition != SearchListBox.Items.Count - 1)
{
SearchListBox.Items.MoveCurrentToNext();
SearchListBox.ScrollIntoView(SearchListBox.Items.CurrentItem);
}
e.Handled = true;
}
if (e.Key == Key.Up)
{
if (SearchListBox.Items.CurrentPosition != 0)
{
SearchListBox.Items.MoveCurrentToPrevious();
SearchListBox.ScrollIntoView(SearchListBox.Items.CurrentItem);
}
e.Handled = true;
}
if (e.Key == Key.Enter) {
txtSearch.Text = this.SearchListBox.SelectedItem.ToString();
this.SearchListBox.Visibility = Visibility.Hidden;
}
}