在 AutoSuggestBox 中浏览建议时显示占位符

Show placeholder when navigating through suggestions in an AutoSuggestBox

是否可以在用户浏览 AutoSuggestBox 建议列表时显示占位符(我的意思是不显示文本框中的任何选定项目)?它与 Windows 10 天气应用程序的功能类似,当用户从搜索框列表中选择一项时,它会在文本框中显示占位符。

Show placeholder when navigating through suggestions in an AutoSuggestBox

好的,AutoSuggestBox contains PlaceholderText 属性,你可以设置它的值或者用c绑定值。

<AutoSuggestBox PlaceholderText="string"/>

when user is selecting one item from the search box list it shows the placeholder in the textbox

当您select建议列表中的选项时,AutoSuggestBox会自动填充TextBox内容(UpdateTextOnSelect),但不是PlaceholderText。如果您现在确实想更改 PlaceholderText,您可以将 UpdateTextOnSelect 设置为 False 并检测 AutoSuggestBox SuggestionChosen 事件,然后在那里设置 PlaceholderText

private void AutoSuggestBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
{
    if (args.SelectedItem is string item)
    {
        sender.Text = string.Empty;
        sender.PlaceholderText = item;
    }
}