如何在建议选择事件中从 c# 设置自动建议框的文本?
How to set the text of an Auto Suggest box from c# in Suggestion Chosen event?
我正在尝试从建议选择事件中隐藏的代码设置自动建议框的文本,但是这样做我的建议列表正在关闭,如果我将文本直接设置为模型名称,则建议列表不会正在关闭。
我想将自动建议框文本设置为模型属性,但如果我这样做,列表将关闭,我不想关闭此事件的建议列表。
另一方面,如果我将文本直接设置为型号名称,那么列表就不会显示 closed.I 我真的很困惑,无法让它发挥作用。
建议选择事件:
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;
}
}
提前致谢。
正如 tushargoyal1309 所说,您可以设置 TextMemberPath 属性 以选择要在文本框中显示的数据对象 属性。更多内容请参考AutoSuggestBox
class官方文档
<AutoSuggestBox
x:Name="asb"
PlaceholderText="Type a name (e.g. John)"
DisplayMemberPath="DisplayName"
TextChanged="asb_TextChanged"
TextMemberPath="DisplayName"
QueryIcon="Find"/>
我正在尝试从建议选择事件中隐藏的代码设置自动建议框的文本,但是这样做我的建议列表正在关闭,如果我将文本直接设置为模型名称,则建议列表不会正在关闭。
我想将自动建议框文本设置为模型属性,但如果我这样做,列表将关闭,我不想关闭此事件的建议列表。
另一方面,如果我将文本直接设置为型号名称,那么列表就不会显示 closed.I 我真的很困惑,无法让它发挥作用。
建议选择事件:
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;
}
}
提前致谢。
正如 tushargoyal1309 所说,您可以设置 TextMemberPath 属性 以选择要在文本框中显示的数据对象 属性。更多内容请参考AutoSuggestBox
class官方文档
<AutoSuggestBox
x:Name="asb"
PlaceholderText="Type a name (e.g. John)"
DisplayMemberPath="DisplayName"
TextChanged="asb_TextChanged"
TextMemberPath="DisplayName"
QueryIcon="Find"/>