Exemple #1
0
        private void UpdateSuggestion(AutoSuggestBox sender)
        {
            try
            {
                var grid              = VisualTreeHelper.GetChild(sender, 0) as Grid;
                var textbox           = grid.Children.First() as TextBox;
                var pointer           = textbox.SelectionStart;
                int selecetedKeyIndex = sender.Text.Take(pointer).Count(o => o == ' ');

                var tags = sender.Text.Split(' ');
                if (tags.Length >= 1 && tags[selecetedKeyIndex] != "")
                {
                    var results = TagDataBase.Search(tags[selecetedKeyIndex]);

                    // Add back the other tags to the string
                    var prefix = String.Join(" ", tags.Take(selecetedKeyIndex));
                    if (!String.IsNullOrWhiteSpace(prefix))
                    {
                        prefix += " ";
                    }
                    var suffix = String.Join(" ", tags.Skip(selecetedKeyIndex + 1));
                    if (!String.IsNullOrWhiteSpace(suffix))
                    {
                        suffix = " " + suffix;
                    }

                    // Also add an extra space at the end so that its easier to start typing next new type
                    var results2 = results.Select(o => new TagDetailInMiddle(o, prefix, suffix + " "));

                    // Display the tag search results
                    sender.ItemsSource = results2;
                }
                else
                {
                    sender.ItemsSource = null;
                }
            }
            catch (Exception ex)
            {
            }
        }
Exemple #2
0
        private void UpdateSuggestion(AutoSuggestBox sender)
        {
            try
            {
                var grid              = VisualTreeHelper.GetChild(sender, 0) as Grid;
                var textbox           = grid.Children.First() as TextBox;
                var pointer           = textbox.SelectionStart;
                int selecetedKeyIndex = sender.Text.Take(pointer).Count(o => o == ' ');

                var tags = sender.Text.Split(' ');
                if (tags.Length >= 1 && tags[selecetedKeyIndex] != "")
                {
                    var result = TagDataBase.Search(tags[selecetedKeyIndex]);
                    sender.ItemsSource = result;
                }
                else
                {
                    sender.ItemsSource = null;
                }
            }
            catch (Exception ex)
            {
            }
        }