【问题标题】:Show placeholder when navigating through suggestions in an AutoSuggestBox在 AutoSuggestBox 中导航建议时显示占位符
【发布时间】:2020-07-09 09:01:13
【问题描述】:

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

【问题讨论】:

    标签: c# xaml uwp win-universal-app windows-10-desktop


    【解决方案1】:

    在 AutoSuggestBox 中导航建议时显示占位符

    当然,AutoSuggestBox 包含 PlaceholderText 属性,你可以设置它的值或用 c 绑定值。

    <AutoSuggestBox PlaceholderText="string"/>
    

    当用户从搜索框列表中选择一项时,它会在文本框中显示占位符

    当您在建议列表中选择选项时,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;
        }
    }
    

    【讨论】:

    • 我认为即使指针只是悬停在某个建议上,他也希望更改占位符文本。
    • 谢谢!这正是我一直在寻找的
    猜你喜欢
    • 2013-06-27
    • 2019-12-21
    • 1970-01-01
    • 1970-01-01
    • 2012-04-14
    • 2017-08-10
    • 2016-08-07
    • 1970-01-01
    相关资源
    最近更新 更多