【问题标题】:Autocomplete textbox in windows phone 8.1windows phone 8.1中的自动完成文本框
【发布时间】:2015-01-21 22:33:18
【问题描述】:

我想在我的 windows phone 8.1 应用程序中添加一些功能,即我的用户输入一些字符,我建议他输入一些单词。

public IEnumerable AutoCompletions = new List<string>()
{
 "Lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit", "Nullam", "felis", "dui", "gravida", "at"};

例如用户输入“a”,我建议“amet”,“at”和“adipiscing”,进一步的用户输入“am”,我建议“amet”。 请帮帮我

【问题讨论】:

标签: windows-phone-8 windows-phone windows-phone-8.1


【解决方案1】:

您要做的是仅显示适用于给定输入的建议。不是所有可能的字符串。

假设您有以下 AutoSuggestBox:

<AutoSuggestBox 
   TextChanged="AutoSuggestBox_TextChanged"
   SuggestionChosen="AutoSuggestBox_SuggestionChosen">
    <AutoSuggestBox.ItemTemplate>
        <DataTemplate>
            <StackPanel Orientation="Horizontal">
                <TextBlock Text="{Binding}" />
            </StackPanel>
        </DataTemplate>
    </AutoSuggestBox.ItemTemplate>
</AutoSuggestBox>

这些是事件处理程序:

private void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
    {
        if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
        {
            // You can set a threshold when to start looking for suggestions
            if (sender.Text.Length > 3)
            {
                sender.ItemsSource = getSuggestions(sender.Text); 
            }
            else {
                sender.ItemsSource = new List<String> { };
            }
        }
    }

您所要做的就是编写一个getSuggestions(String text) 方法,该方法返回给定输入的合理建议。

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-04-13
  • 1970-01-01
  • 1970-01-01
  • 2016-07-30
  • 1970-01-01
相关资源
最近更新 更多