UWP-C#-如何在AutoSearchBox中编程模拟SugestHosen?

UWP-C#-如何在AutoSearchBox中编程模拟SugestHosen?,c#,uwp,barcode,C#,Uwp,Barcode,我使用自动搜索框来查找产品。我可以按姓名或ID搜索。现在,我想添加一个条形码扫描仪以加快发票注册。获取条形码后,我得到了产品,但我不知道如何获取SugestOnChosen事件,以便在ItemsSource中获取SelectedItem。通常,当用户在自动搜索框列表中选择一个选项时,会发生这种情况。你知道如何解决这个要求吗 private void ProductSearchBox_TextChanged(AutoSuggestBox sender, Auto

我使用自动搜索框来查找产品。我可以按姓名或ID搜索。现在,我想添加一个条形码扫描仪以加快发票注册。获取条形码后,我得到了产品,但我不知道如何获取SugestOnChosen事件,以便在ItemsSource中获取SelectedItem。通常,当用户在自动搜索框列表中选择一个选项时,会发生这种情况。你知道如何解决这个要求吗

    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
              //

            }
        }
    }

正如@Faywang所说,“您可以通过ViewModel.SearchingProducto(productName)和var model=ViewModel.ProductSuggestions[0];”获取产品模型。ProductSuggestions通过条形码扫描只会有一个产品,因此第一个元素是您扫描的模型”

扫描代码后调用事件即可?如果您需要更多帮助,请共享相关代码。您的意思是,当您通过条形码获取产品(如productName)时,是否希望获取与产品名称对应的产品型号?如果是,您可以通过
ViewModel.SearchingProducto(productName)获取产品型号
var模型=ViewModel.ProductSuggestions[0]
.ProductSuggestions通过条形码扫描只会有一个产品,因此第一个元素是您扫描的模型。如果没有,您能更详细地描述场景吗?@Faywang我已经采取了这种方法,效果很好!谢谢