【问题标题】:AutoSuggestBox implementation in windows 8.1Windows 8.1 中的 AutoSuggestBox 实现
【发布时间】:2015-06-08 13:07:58
【问题描述】:

我需要在 Windows 8.1 应用程序中实现 AutoSuggestBox。我的目标是有一个文本框,它建议并自动完成用户输入的文本。

作为一个新手,我对应用程序开发了解不多。我也不熟悉数据绑定,这似乎对此至关重要。所以请保持简单。

【问题讨论】:

    标签: xaml autocomplete windows-8.1 windows-applications autosuggest


    【解决方案1】:

    示例背后的简单代码。

    MainPage.xaml.cs

        public ObservableCollection<string> Items { get; private set; }
    
        public MainPage()
        {
            this.InitializeComponent();
    
            Items = new ObservableCollection<string>
            {
                "test",
                "new",
                "to",
                "test1"
            };
        }
    
        private void autosuggest_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
        {
            List<string> myList = new List<string>();
            foreach (string myString in Items)
            {
                if (myString.Contains(sender.Text) == true)
                {
                    myList.Add(myString);
                }
            }
            sender.ItemsSource = myList;
        }
    

    MainPage.xaml

    <AutoSuggestBox x:Name="autosuggest" Foreground="White" TextChanged="autosuggest_TextChanged" />
    

    【讨论】:

      猜你喜欢
      • 2014-12-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-12-08
      • 1970-01-01
      相关资源
      最近更新 更多