Xaml UWP应用程序如何选择AutoSuggestBox生成图像
我想在其中一个字符串上激活UWP应用程序AutoSuggestBox时在搜索栏下方显示一个图像,但我不知道如何在不导致程序中断的情况下执行该操作 我目前有一个列表,可以获取名称并将其显示在下拉列表中,但是当我试图更改QuerySubmitted时,单击Enter或单击search选项不会导致任何事情发生(由于缺少信息),因为语句导致程序出现严重错误 前端代码Xaml UWP应用程序如何选择AutoSuggestBox生成图像,xaml,Xaml,我想在其中一个字符串上激活UWP应用程序AutoSuggestBox时在搜索栏下方显示一个图像,但我不知道如何在不导致程序中断的情况下执行该操作 我目前有一个列表,可以获取名称并将其显示在下拉列表中,但是当我试图更改QuerySubmitted时,单击Enter或单击search选项不会导致任何事情发生(由于缺少信息),因为语句导致程序出现严重错误 前端代码 <AutoSuggestBox PlaceholderText="What do you want to
<AutoSuggestBox PlaceholderText="What do you want to eat?" QueryIcon="Find" Name="MainSearchBar"
TextChanged="AutoSuggestBox_TextChanged"
QuerySubmitted="AutoSuggestBox_QuerySubmitted"
SuggestionChosen="AutoSuggestBox_SuggestionChosen" Grid.ColumnSpan="3" Height="38" Margin="47,42,187,0"/>
后端XAML代码
List<string> suggestionListTest = null;
private void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
{
// Only get results when it was a user typing,
// otherwise assume the value got filled in by TextMemberPath
// or the handler for SuggestionChosen.
if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
{
//Set the ItemsSource to be your filtered dataset
//sender.ItemsSource = dataset;
if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
{
List<string> _nameList = new List<string>();
_nameList.Add("Santhakumar");
_nameList.Add("Vishanth");
_nameList.Add("Dinesh");
_nameList.Add("Srinivasan");
_nameList.Add("Nandhakumar");
suggestionListTest = _nameList.Where(x => x.StartsWith(sender.Text)).ToList();
sender.ItemsSource = suggestionListTest;
}
//else
//{
// sender.ItemsSource = new string[] { "No Suggestions Available" };
//}
}
}
private void AutoSuggestBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
{
var selectedItem = args.SelectedItem.ToString();
sender.Text = selectedItem;
}
private void AutoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
{
if (args.ChosenSuggestion != null)
{
MainSearchBar.Text = args.ChosenSuggestion.ToString();
}
//else
//{
//}
}
List suggestionListTest=null;
私有void AutoSuggestBox_TextChanged(AutoSuggestBox发件人、AutoSuggestBoxTextChangedEventArgs)
{
//仅当用户键入时才能获取结果,
//否则,假设该值由TextMemberPath填充
//或者选择SuggestionSelected的处理程序。
if(args.Reason==AutoSuggestionBoxTextChangeReason.UserInput)
{
//将ItemsSource设置为筛选的数据集
//sender.ItemsSource=数据集;
if(args.Reason==AutoSuggestionBoxTextChangeReason.UserInput)
{
列表_nameList=新列表();
_姓名列表。添加(“Santhakumar”);
_姓名列表。添加(“Vishanth”);
_姓名列表。添加(“Dinesh”);
_姓名列表。添加(“Srinivasan”);
_姓名列表。添加(“Nandhakumar”);
suggestionListTest=_nameList.Where(x=>x.StartsWith(sender.Text)).ToList();
sender.ItemsSource=suggestionListTest;
}
//否则
//{
//sender.ItemsSource=新字符串[]{“无可用建议”};
//}
}
}
private void AutoSuggestBox\u SuggestionSelected(AutoSuggestBox发件人、AutoSuggestBoxSuggestionChosenEventArgs args args)
{
var selectedItem=args.selectedItem.ToString();
sender.Text=selectedItem;
}
私有void AutoSuggestBox_QuerySubmitted(AutoSuggestBox发送方、AutoSuggestBox querysubmittedventargs args)
{
if(args.ChosenSuggestion!=null)
{
MainSearchBar.Text=args.ChosenSuggestion.ToString();
}
//否则
//{
//}
}