共用方式為


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

取得網際網路工程工作組 (IETF) 語言標記, (BCP 47 標準) ,識別目前與使用者文字輸入裝置相關聯的語言。

LinguisticDetails

取得使用者透過輸入法編輯器輸入 (輸入法) 查詢文字的相關資訊。

QueryText

取得目前搜尋的查詢文字。

Request

取得 物件,這個物件會儲存此要求的建議和資訊。

適用於

另請參閱