Пример #1
0
        public async Task StartSearch(string startingText = "")
        {
            if (_searchBox == null || _searchBox.Visibility == Visibility.Visible)
            {
                return;
            }

            HideSamplePicker();
            HamburgerMenu.IsPaneOpen = true;
            _searchBox.Text          = startingText;

            _searchButton.Visibility = Visibility.Collapsed;
            _searchBox.Visibility    = Visibility.Visible;

            // We need to wait for the textbox to be created to focus it (only first time).
            TextBox innerTextbox = null;

            do
            {
                innerTextbox = _searchBox.FindDescendant <TextBox>();
                innerTextbox?.Focus(FocusState.Programmatic);

                if (innerTextbox == null)
                {
                    await Task.Delay(150);
                }
            }while (innerTextbox == null);
        }
        private void UpdateTokensCounter(TokenizingTextBoxItem ttbi)
        {
            var maxTokensCounter = (TextBlock)_autoSuggestBox?.FindDescendant(PART_TokensCounter);

            if (maxTokensCounter == null)
            {
                return;
            }

            void OnTokenCountChanged(TokenizingTextBox ttb, object value = null)
            {
                var itemsSource   = ttb.ItemsSource as InterspersedObservableCollection;
                var currentTokens = itemsSource.ItemsSource.Count;
                var maxTokens     = ttb.MaximumTokens;

                maxTokensCounter.Text       = $"{currentTokens}/{maxTokens}";
                maxTokensCounter.Visibility = Visibility.Visible;

                maxTokensCounter.Foreground = (currentTokens >= maxTokens)
                    ? new SolidColorBrush(Colors.Red)
                    : _autoSuggestBox.Foreground;
            }

            ttbi.Owner.TokenItemAdded   -= OnTokenCountChanged;
            ttbi.Owner.TokenItemRemoved -= OnTokenCountChanged;

            if (Content is ITokenStringContainer str && str.IsLast && ttbi?.Owner != null && ttbi.Owner.ReadLocalValue(TokenizingTextBox.MaximumTokensProperty) != DependencyProperty.UnsetValue)
            {
                ttbi.Owner.TokenItemAdded   += OnTokenCountChanged;
                ttbi.Owner.TokenItemRemoved += OnTokenCountChanged;
                OnTokenCountChanged(ttbi.Owner);
            }
        private void PrimaryWindowCoreLayout_Loaded(object sender, RoutedEventArgs e)
        {
            var textBox = AutoSuggestBox.FindDescendant <TextBox>();

            textBox.TextCompositionStarted += TextBox_TextCompositionStarted;
            textBox.TextCompositionEnded   += TextBox_TextCompositionEnded;
            textBox.TextChanged            += TextBox_TextChanged;
        }
Пример #4
0
        private void ConnectToSearch()
        {
            var searchButton = HamburgerMenu.FindDescendantByName("SearchButton") as Button;

            _searchBox = HamburgerMenu.FindDescendantByName("SearchBox") as AutoSuggestBox;

            if (_searchBox == null || searchButton == null)
            {
                return;
            }

            searchButton.Click += async(sender, args) =>
            {
                HamburgerMenu.IsPaneOpen = true;
                _searchBox.Text          = string.Empty;

                // We need to wait for the textbox to be created to focus it (only first time).
                TextBox innerTextbox = null;

                do
                {
                    innerTextbox = _searchBox.FindDescendant <TextBox>();
                    innerTextbox?.Focus(FocusState.Programmatic);

                    if (innerTextbox == null)
                    {
                        await Task.Delay(150);
                    }
                }while (innerTextbox == null);
            };

            _searchBox.DisplayMemberPath = "Name";
            _searchBox.TextMemberPath    = "Name";

            _searchBox.QuerySubmitted += (sender, args) =>
            {
                var sample = args.ChosenSuggestion as Sample;
                if (sample != null)
                {
                    NavigateToSample(sample);
                }
                else
                {
                    NavigationFrame.Navigate(typeof(SamplePicker), _searchBox.Text);
                }
            };

            _searchBox.TextChanged += (sender, args) =>
            {
                if (args.Reason != AutoSuggestionBoxTextChangeReason.UserInput)
                {
                    return;
                }

                UpdateSearchSuggestions();
            };
        }
Пример #5
0
        private void OnASBLoaded(object sender, RoutedEventArgs e)
        {
            if (_autoSuggestTextBox != null)
            {
                _autoSuggestTextBox.PreviewKeyDown -= this.AutoSuggestTextBox_PreviewKeyDown;
            }

            _autoSuggestTextBox = _autoSuggestBox.FindDescendant <TextBox>() as TextBox;
            _autoSuggestTextBox.PreviewKeyDown += this.AutoSuggestTextBox_PreviewKeyDown;
        }
        private void OnASBLoaded(object sender, RoutedEventArgs e)
        {
            UpdateTokensCounter(this);

            // Local function for Selection changed
            void AutoSuggestTextBox_SelectionChanged(object box, RoutedEventArgs args)
            {
                if (!(IsAllSelected || TokenizingTextBox.IsShiftPressed || Owner.IsClearingForClick))
                {
                    Owner.DeselectAllTokensAndText(this);
                }

                // Ensure flag is always reset
                Owner.IsClearingForClick = false;
            }

            // local function for clearing selection on interaction with text box
            async void AutoSuggestTextBox_TextChangingAsync(TextBox o, TextBoxTextChangingEventArgs args)
            {
                // remove any selected tokens.
                if (Owner.SelectedItems.Count > 1)
                {
                    await Owner.RemoveAllSelectedTokens();
                }
            }

            if (_autoSuggestTextBox != null)
            {
                _autoSuggestTextBox.PreviewKeyDown    -= this.AutoSuggestTextBox_PreviewKeyDown;
                _autoSuggestTextBox.TextChanging      -= AutoSuggestTextBox_TextChangingAsync;
                _autoSuggestTextBox.SelectionChanged  -= AutoSuggestTextBox_SelectionChanged;
                _autoSuggestTextBox.SelectionChanging -= AutoSuggestTextBox_SelectionChanging;
            }

            _autoSuggestTextBox = _autoSuggestBox.FindDescendant <TextBox>() as TextBox;

            if (_autoSuggestTextBox != null)
            {
                _autoSuggestTextBox.PreviewKeyDown    += this.AutoSuggestTextBox_PreviewKeyDown;
                _autoSuggestTextBox.TextChanging      += AutoSuggestTextBox_TextChangingAsync;
                _autoSuggestTextBox.SelectionChanged  += AutoSuggestTextBox_SelectionChanged;
                _autoSuggestTextBox.SelectionChanging += AutoSuggestTextBox_SelectionChanging;

                AutoSuggestTextBoxLoaded?.Invoke(this, e);
            }
        }
Пример #7
0
        public async Task StartSearch(string startingText = null)
        {
            if (_searchBox == null || _searchBox.Visibility == Visibility.Visible)
            {
                return;
            }

            var currentSearchText = _searchBox.Text;

            _searchBox.Text = string.Empty;

            if (!string.IsNullOrWhiteSpace(startingText))
            {
                _searchBox.Text = startingText;
            }
            else
            {
                _searchBox.Text = currentSearchText;
            }

            _searchButton.Visibility = Visibility.Collapsed;
            _searchBox.Visibility    = Visibility.Visible;

            _searchBox.Focus(FocusState.Programmatic);

            // We need to wait for the textbox to be created to focus it (only first time).
            TextBox innerTextbox = null;

            do
            {
                innerTextbox = _searchBox.FindDescendant <TextBox>();
                innerTextbox?.Focus(FocusState.Programmatic);

                if (innerTextbox == null)
                {
                    await Task.Delay(150);
                }
            }while (innerTextbox == null);
        }