SearchBoxSuggestionsRequestedEventArgs 类

定义

提供 SearchBox.SuggestionsRequested 事件的事件数据。

public ref class SearchBoxSuggestionsRequestedEventArgs sealed
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
/// [Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
class SearchBoxSuggestionsRequestedEventArgs final
/// [Windows.Foundation.Metadata.ContractVersion(Windows.Foundation.UniversalApiContract, 65536)]
/// [Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
class SearchBoxSuggestionsRequestedEventArgs final
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
[Windows.Foundation.Metadata.Threading(Windows.Foundation.Metadata.ThreadingModel.Both)]
public sealed class SearchBoxSuggestionsRequestedEventArgs
[Windows.Foundation.Metadata.ContractVersion(typeof(Windows.Foundation.UniversalApiContract), 65536)]
[Windows.Foundation.Metadata.MarshalingBehavior(Windows.Foundation.Metadata.MarshalingType.Agile)]
public sealed class SearchBoxSuggestionsRequestedEventArgs
Public NotInheritable Class SearchBoxSuggestionsRequestedEventArgs
继承
Object Platform::Object IInspectable SearchBoxSuggestionsRequestedEventArgs
属性

Windows 要求

设备系列
Windows 10 (在 10.0.10240.0 中引入)
API contract
Windows.Foundation.UniversalApiContract (在 v1.0 中引入)

示例

如果要异步响应 SuggestionsRequested 事件,则必须在编辑建议列表之前获取 SearchSuggestionsRequestDeferral 对象。 下面是一个演示方法的示例。

public async static void SearchBox_SuggestionsRequested(
    SearchBox sender, 
    SearchBoxSuggestionsRequestedEventArgs args)
{

    // This object lets us edit the SearchSuggestionCollection asynchronously. 
    var deferral = args.Request.GetDeferral();

    try { 

        // Retrieve the system-supplied suggestions.
        var suggestions = args.Request.SearchSuggestionCollection;

        var groups = await SampleDataSource.GetGroupsAsync();
        foreach (var group in groups)
        {
            var matchingItems = group.Items.Where(
                item => item.Title.StartsWith(
                    args.QueryText, StringComparison.CurrentCultureIgnoreCase));

            foreach (var item in matchingItems)
            {
                suggestions.AppendQuerySuggestion(item.Title);
            }
        }

        foreach (string alternative in args.LinguisticDetails.QueryTextAlternatives)
        {
            if (alternative.StartsWith(
                args.QueryText, StringComparison.CurrentCultureIgnoreCase))
            {
                suggestions.AppendQuerySuggestion(alternative); 
            }
        }
    }
    finally {
        deferral.Complete();
    }

}

注解

重要

尽管已在通用设备系列中实现了 SearchBox,但它无法在移动设备上正常运行。 将 AutoSuggestBox 用于通用搜索体验。 请参阅弃用 SearchBox 以支持 AutoSuggestBox

属性

Language

获取 Internet 工程任务组 (IETF) 语言标记 (BCP 47 标准) ,该标记标识当前与用户的文本输入设备关联的语言。

LinguisticDetails

获取有关用户通过输入法编辑器输入的查询文本的信息, (输入法) 。

QueryText

获取当前搜索的查询文本。

Request

获取对象,该对象存储有关此请求的建议和信息。

适用于

另请参阅