private void txtBarcode_PreviewKeyDown(object sender, KeyEventArgs e) { if (e.Key == Key.Enter) { if (!stock.GetStock(this.txtBarcode.Text.Trim())) { MessageBox.Show("条码错误或商品库存不足!", "错误", MessageBoxButton.OK, MessageBoxImage.Error); this.txtBarcode.SelectAll(); } else { this.txtBarcode.Text = string.Empty; } e.Handled = true; } }