设为首页 加入收藏

TOP

【Win10开发】关于AutoSuggestBox
2017-10-11 16:05:20 】 浏览:254
Tags:Win10 开发 关于 AutoSuggestBox

其实看名字我们就知道,这个控件可以提供一些建议文本。我们在做搜索框时可以做一些文本来让用户选择。

这个控件有两个关键的事件QuerySubmittedSuggestionChosen事件,当下拉列表中的项被选择后,会发生SuggestionChosen事件。当在下拉列表中做出选择后会提交输入的文本,这时候会发生QuerySubmitted事件,从事件参数的QueryText属性可以获取输入框中要提交的查询文本。


我们做个查询单词的小例子吧,首先看看效果。

那么,现在先进行xaml布局。

1         <StackPanel HorizontalAlignment="Center" Width="400">
2             <AutoSuggestBox Name="search" QueryIcon="Find" PlaceholderText="请输入一个单词"
3                         QuerySubmitted="search_QuerySubmitted" SuggestionChosen="search_SuggestionChosen">
4             </AutoSuggestBox>
5             <TextBlock Name="content" FontSize="40" Foreground="LightBlue"/>
6         </StackPanel>  

 接下来,我们为AutoSuggestBox控件设置下拉列表,用ItemsSource属性来指定数据源。

        string[] array = new string[]
        {
                "auto","suggest","search","page","surface","microsoft","keyboard","help"
        };
        ...

        search.ItemsSource = array;

处理SuggestionChosen事件

1         private void search_SuggestionChosen(Windows.UI.Xaml.Controls.AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args)
2         {
3             string s = args.SelectedItem as string;
4             sender.Text = s;
5         }

处理QuerySubmitted事件

        private void search_QuerySubmitted(Windows.UI.Xaml.Controls.AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
        {
            content.Text = $"{args.QueryText}";
        }

 至此,这个小例子就完成了。

】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇01.移动先行之谁主沉浮----我的第.. 下一篇xaml中按比例设定Grid的行或列的..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目