private void AutoSuggestBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args) { AddToken(args.SelectedItem); sender.Text = string.Empty; sender.Focus(FocusState.Programmatic); SuggestionChosen?.Invoke(sender, args); }
private void ChoseItem(Object o) { if (UpdateTextOnSelect) { UpdateTextFromSuggestion(o); } SuggestionChosen?.Invoke(this, new AutoSuggestBoxSuggestionChosenEventArgs(o)); }
private void OnSuggestionListItemClick(object sender, ItemClickEventArgs e) { if (this.Log().IsEnabled(Microsoft.Extensions.Logging.LogLevel.Debug)) { this.Log().Debug($"Suggestion item clicked {e.ClickedItem}"); } SuggestionChosen?.Invoke(this, new AutoSuggestBoxSuggestionChosenEventArgs(e.ClickedItem)); IsSuggestionListOpen = false; }
/// <summary> /// Initializes a new instance of the <see cref="AutoSuggestBox"/> class /// </summary> public AutoSuggestBox() { NativeAutoSuggestBox = new NativeAutoSuggestBox( Android.App.Application.Context ); NativeAutoSuggestBox.SuggestionChosen += (s, e) => { SuggestionChosen?.Invoke(this, new AutoSuggestBoxSuggestionChosenEventArgs(e.SelectedItem)); }; NativeAutoSuggestBox.TextChanged += (s, e) => { suppressTextChangedEvent = true; Text = NativeAutoSuggestBox.Text; suppressTextChangedEvent = false; TextChanged?.Invoke(this, new AutoSuggestBoxTextChangedEventArgs((AutoSuggestionBoxTextChangeReason)e.Reason)); }; NativeAutoSuggestBox.QuerySubmitted += (s, e) => QuerySubmitted?.Invoke(this, new AutoSuggestBoxQuerySubmittedEventArgs(e.QueryText, e.ChosenSuggestion)); }
protected override void OnApplyTemplate() { _borderElement = base.GetTemplateChild("BorderElement") as Border; _autoSuggestBox = base.GetTemplateChild("AutoSuggestBox") as AutoSuggestBox; _displayContent = base.GetTemplateChild("DisplayContent") as Border; _autoSuggestBox.TextChanged += (s, a) => TextChanged?.Invoke(s, a); _autoSuggestBox.SuggestionChosen += (s, a) => SuggestionChosen?.Invoke(s, a); _autoSuggestBox.QuerySubmitted += (s, a) => QuerySubmitted?.Invoke(s, a); _isInitialized = true; UpdateMode(); UpdateVisualState(); base.OnApplyTemplate(); }
/// <summary> /// Initializes a new instance of the <see cref="AutoSuggestBox"/> class /// </summary> public AutoSuggestBox() { #if !NETSTANDARD2_0 NativeAutoSuggestBox = new NativeAutoSuggestBox( #if __ANDROID__ Android.App.Application.Context #endif ); NativeAutoSuggestBox.SuggestionChosen += (s, e) => { SuggestionChosen?.Invoke(this, new AutoSuggestBoxSuggestionChosenEventArgs(e.SelectedItem)); }; NativeAutoSuggestBox.TextChanged += (s, e) => { suppressTextChangedEvent = true; Text = NativeAutoSuggestBox.Text; suppressTextChangedEvent = false; TextChanged?.Invoke(this, new AutoSuggestBoxTextChangedEventArgs((AutoSuggestionBoxTextChangeReason)e.Reason)); }; NativeAutoSuggestBox.QuerySubmitted += (s, e) => QuerySubmitted?.Invoke(this, new AutoSuggestBoxQuerySubmittedEventArgs(e.QueryText, e.ChosenSuggestion)); #else throw new PlatformNotSupportedException(); #endif }
protected override void OnApplyTemplate() { base.OnApplyTemplate(); _container = base.GetTemplateChild("container") as Grid; _autoSuggestBox = base.GetTemplateChild("autoSuggestBox") as AutoSuggestBox; _displayText = base.GetTemplateChild("displayText") as TextBlock; _border = base.GetTemplateChild("border") as Border; _container.PointerEntered += OnPointerEntered; _container.PointerExited += OnPointerExited; _autoSuggestBox.GotFocus += OnGotFocus; _autoSuggestBox.LostFocus += OnLostFocus; _autoSuggestBox.TextChanged += (s, a) => TextChanged?.Invoke(s, a); _autoSuggestBox.SuggestionChosen += (s, a) => SuggestionChosen?.Invoke(s, a); _autoSuggestBox.QuerySubmitted += (s, a) => QuerySubmitted?.Invoke(s, a); UpdateMode(); }
private void OnSuggestionsListSelectionChanged(object sender, SelectionChangedEventArgs e) { if (m_ignoreSelectionChange) { return; } if (IsSuggestionListOpen) { var selectedItem = m_suggestionsList.SelectedItem; if (selectedItem != null) { m_suggestionsList.ScrollIntoView(selectedItem); SuggestionChosen?.Invoke(this, new AutoSuggestBoxSuggestionChosenEventArgs { SelectedItem = selectedItem }); if (UpdateTextOnSelect) { var selectedValue = m_suggestionsList.SelectedValue; if (selectedValue != null) { UpdateTextValue(selectedValue.ToString(), AutoSuggestionBoxTextChangeReason.SuggestionChosen); } } } else { m_suggestionsList.ScrollToTop(); UpdateTextValue(m_searchText); } if (m_textBox != null) { m_textBox.CaretIndex = m_textBox.Text.Length; } } }
internal void RaiseSuggestionChosen(object selectedItem) { SuggestionChosen?.Invoke(this, new AutoSuggestBoxSuggestionChosenEventArgs(selectedItem)); }
internal void RaiseSuggestionChosen(object selectedItem) { SuggestionChosen?.Invoke(this, new AutoCompleteViewEventArgs(selectedItem)); }
internal void RaiseSuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args) { SuggestionChosen?.Invoke(sender, args); }
public void FireSuggestionChosen(AutoSuggestBoxSuggestionChosenEventArgs args) { SuggestionChosen?.Invoke(this, args); }
private void AutoSuggestBox_SuggestionChosen(AutoSuggestBox sender, AutoSuggestBoxSuggestionChosenEventArgs args) { SuggestionChosen?.Invoke(sender, args); }
internal async Task CommitSuggestionAsync(object selectedItem) { var currentQuery = _currentQuery; var range = currentQuery?.Range.GetClone(); var id = Guid.NewGuid(); var prefix = currentQuery?.Prefix; var query = currentQuery?.QueryText; // range has length of 0 at the end of the commit. // Checking length == 0 to avoid committing twice. if (prefix == null || query == null || range == null || range.Length == 0) { return; } var textBefore = range.Text; var format = CreateTokenFormat(range); var eventArgs = new SuggestionChosenEventArgs { Id = id, Prefix = prefix, QueryText = query, SelectedItem = selectedItem, DisplayText = query, Format = format }; if (SuggestionChosen != null) { await SuggestionChosen.InvokeAsync(this, eventArgs); } var text = eventArgs.DisplayText; // Since this operation is async, the document may have changed at this point. // Double check if the range still has the expected query. if (string.IsNullOrEmpty(text) || textBefore != range.Text || !TryExtractQueryFromRange(range, out var testPrefix, out var testQuery) || testPrefix != prefix || testQuery != query) { return; } var displayText = prefix + text; void RealizeToken() { if (TryCommitSuggestionIntoDocument(range, displayText, id, eventArgs.Format ?? format, true)) { var token = new RichSuggestToken(id, displayText) { Active = true, Item = selectedItem }; token.UpdateTextRange(range); _tokens.Add(range.Link, token); } } lock (_tokensLock) { this.CreateSingleEdit(RealizeToken); } }