我正在尝试从Suggestion Chosen事件中的代码后面设置Auto Suggest框的文本但是这样做我的建议列表正在关闭,如果我将文本直接设置为模型名称,那么建议列表不会被关闭
我想将自动建议框文本设置为模型属性,但如果我这样做,则列表正在关闭,我不想关闭此事件的建议列表。
另一方面,如果我将文本直接设置为模型名称,那么列表就不会被关闭。我真的很困惑让它工作。
建议选择事件:
private void recipient_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
{
var getType = args.SelectedItem.GetType();
if (getType.Name == "Table_People")
{
var selectedItemRecipient = args.SelectedItem as Table_People;
//By doing this the list is getting closed.
sender.Text = selectedItemRecipient.FirstName + " " + selectedItemRecipient.LastName;
recipienterror.Visibility = Visibility.Collapsed;
_personID = selectedItemRecipient.PersonID;
}
else
{
var selectedItemRecipientPlaces = args.SelectedItem as Table_Places;
_placeID = selectedItemRecipientPlaces.PlaceID;
//By doing this the list is getting closed.
sender.Text = selectedItemRecipientPlaces.FirstName + " " + selectedItemRecipientPlaces.LastName;
recipienterror.Visibility = Visibility.Collapsed;
}
}
提前致谢。
答案 0 :(得分:1)
正如tushargoyal1309所说,您可以设置TextMemberPath属性以选择数据对象中的哪个属性显示在文本框中。有关更多信息,请参阅AutoSuggestBox
类官方文档。
<AutoSuggestBox
x:Name="asb"
PlaceholderText="Type a name (e.g. John)"
DisplayMemberPath="DisplayName"
TextChanged="asb_TextChanged"
TextMemberPath="DisplayName"
QueryIcon="Find"/>