【发布时间】:2019-08-29 15:54:24
【问题描述】:
我使用自动搜索框来查找产品。我可以按名称或 ID 搜索。现在,我想添加一个条形码扫描仪来加快发票登记。获取条形码后,我得到了产品,但我不知道如何获取 SugestionChosen 事件以获取 ItemsSource 中的 SelectedItem。当用户在 AutoSearchBox 列表中选择一个选项时,通常会发生这种情况。你知道如何解决这个要求吗?
private void ProductSearchBox_TextChanged(AutoSuggestBox sender,
AutoSuggestBoxTextChangedEventArgs args)
{
if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
{
// here look for products
ViewModel.SearchingProducto(sender.Text);
sender.ItemsSource = ViewModel.ProductSuggestions;
// if there is only one coincidence and length match with lenght
// barcode
if (ViewModel.ProductSuggestions.Count == 1 &
ProductSearchBox.Text.Length == 13)
{
//
// Here I want to simulate SugestionChosen event in order to
// get the product which barcode matchs
//
}
}
}
【问题讨论】:
-
扫码后调用事件?如果您需要更多帮助,请分享相关代码。
-
您的意思是当您通过条码获取产品(例如productName)时,您想获取产品名称对应的产品型号吗?如果是,您可以通过
ViewModel.SearchingProducto(productName);获取产品型号和var model = ViewModel.ProductSuggestions[0];.ProductSuggestions通过条码扫描只会有一个产品,所以第一个元素是你扫描的模型。如果没有,你能更详细地描述一下场景吗? -
@Faywang Effectevely 我采用了这种方法,效果很好!谢谢。