Ejemplo n.º 1
0
        private void SearchButton_Click(object sender, RoutedEventArgs e)
        {
            FileManager.itemViewHolder.IsBackButtonEnabled            = true;
            FileManager.itemViewHolder.SearchButtonVisibility         = false;
            FileManager.itemViewHolder.SearchAutoSuggestBoxVisibility = true;

            // slightly delay setting focus
            Task.Factory.StartNew(
                () => Dispatcher.RunAsync(CoreDispatcherPriority.Low,
                                          () => SearchAutoSuggestBox.Focus(FocusState.Programmatic)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// 语音搜索
        /// </summary>
        /// <param name="searchItem">搜索内容</param>
        public async void VoiceSearch(string searchItem)
        {
            SuggestBoxItem suggestBoxItem = null;
            await Global.SetAutoSuggestBoxItem();

            var searchItemToLower = searchItem.Trim().ToLower();

            if (string.IsNullOrEmpty(searchItemToLower))
            {
                return;
            }
            for (var i = Global.AutoSuggestBoxItem.Count - 1; i >= 0; i--)
            {
                if (Global.AutoSuggestBoxItem[i].Name.ToLower().IndexOf(searchItemToLower, StringComparison.Ordinal) < 0 && Global.AutoSuggestBoxItem[i].EnName.ToLower().IndexOf(searchItemToLower, StringComparison.Ordinal) < 0)
                {
                    Global.AutoSuggestBoxItem.Remove(Global.AutoSuggestBoxItem[i]);
                }
            }
            if (Global.AutoSuggestBoxItem.Count == 0)
            {
                SearchAutoSuggestBox.Text = "";
                var dialog = new ContentDialog
                {
                    Title             = "搜索错误!",
                    Content           = "未找到“" + searchItem + "”",
                    PrimaryButtonText = "确定",
                    FullSizeDesired   = false
                };
                Global.ShowDialog(dialog);
            }
            else if (Global.AutoSuggestBoxItem.Count == 1)
            {
                suggestBoxItem            = Global.AutoSuggestBoxItem[0];
                SearchAutoSuggestBox.Text = searchItem;
            }
            else if (Global.AutoSuggestBoxItem.Count > 1)
            {
                SearchAutoSuggestBox.Text = searchItem;
                SearchAutoSuggestBox.Focus(FocusState.Programmatic);
            }
            // 搜索结果唯一时suggestBoxItem获得数据
            if (suggestBoxItem != null)
            {
                AutoSuggestNavigate(new SearchExtraData
                {
                    SourcePath = suggestBoxItem.SourcePath,
                    Picture    = suggestBoxItem.Picture,
                    Category   = suggestBoxItem.Category
                });
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// 搜索框查询提交事件
        /// </summary>
        private void SearchAutoSuggestBox_QuerySubmitted(AutoSuggestBox sender, AutoSuggestBoxQuerySubmittedEventArgs args)
        {
            Global.AutoSuggestBoxItem.Clear();
            foreach (var item in Global.AutoSuggestBoxItemSource)
            {
                Global.AutoSuggestBoxItem.Add(item);
            }
            var str = sender.Text.Trim().ToLower();

            if (string.IsNullOrEmpty(str))
            {
                return;
            }
            for (var i = Global.AutoSuggestBoxItem.Count - 1; i >= 0; i--)
            {
                if (Global.AutoSuggestBoxItem[i].Name.ToLower().IndexOf(str, StringComparison.Ordinal) < 0 && Global.AutoSuggestBoxItem[i].EnName.ToLower().IndexOf(str, StringComparison.Ordinal) < 0)
                {
                    Global.AutoSuggestBoxItem.Remove(Global.AutoSuggestBoxItem[i]);
                }
            }
            if (sender.Items != null && sender.Items.Count != 0 && args.ChosenSuggestion == null)
            {
                if (Global.AutoSuggestBoxItem.Count > 1)
                {
                    SearchAutoSuggestBox.Focus(FocusState.Programmatic);
                }
                else
                {
                    var suggestBoxItem = (SuggestBoxItem)sender.Items[0];
                    if (suggestBoxItem != null)
                    {
                        AutoSuggestNavigate(new SearchExtraData
                        {
                            SourcePath = suggestBoxItem.SourcePath,
                            Picture    = suggestBoxItem.Picture,
                            Category   = suggestBoxItem.Category
                        });
                        SearchAutoSuggestBox.Text = suggestBoxItem.Name;
                    }
                }
            }
        }