Forum Xamarin.Forms

Auto Suggest Entry in xamarin forms

umemariyamumemariyam USMember ✭✭

I am trying to create a AutoComplete Text Entry using Xamarin Forms. I was able to accomplish the functionality using dotmorten.xamarin.forms.autosuggestbox. The issue that I am facing is I am unable to change the font size and border width using this control. I want it to look like a entry field with only bottom border but it looks more like a Box entry. Is there a way to customize it or is there any other control/way to achieve similar functionality.

Any help is appreciated!

Best Answer

Answers

  • umemariyamumemariyam USMember ✭✭

    Hi Colex,
    When I am trying to create a custom control and inheriting AutoSuggestBox it is not accepting("AutoSuggestBox" could not be found). as it is not supported in xamarin. AutoSuggestBoxRenderer is also not supported.

  • ColeXColeX Member, Xamarin Team Xamurai
    edited May 2019
    Add `dotmorten.xamarin.forms.autosuggestbox` package into your project first.
  • ColeXColeX Member, Xamarin Team Xamurai

    Attached my sample .

  • umemariyamumemariyam USMember ✭✭

    @ Colex It is working but the list which appears below the text box is not appearing now.
    is there any modification required in resource file?

  • ColeXColeX Member, Xamarin Team Xamurai
    edited May 2019

    You have to specify the itemsSource code hehind.

            List<string> list = new List<string>();
            list.Add("111");
            list.Add("222");
            list.Add("3331");
    
            box.ItemsSource = list;   //box is the name of autoSuggestbox.
    

    And filter data in the method AutoSuggestBox_TextChanged

     private void AutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs args)
        {
            if (args.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
            {
                var filtered = list.Where(i => i.Contains(this.box.Text)).ToList();
                box.ItemsSource = filtered;
            }
        }
    
  • umemariyamumemariyam USMember ✭✭
    edited May 2019

    Colex. I have already specified the itemsSource like below. But when I type something in the textbox there is a line which appears above the textbox but list wont appear

    public void CustSuggestionBox_TextChanged(object param)
            {
                try
                {
                    SelectedCustomerName = param.ToString();
                    var customerData = GetCustomerSuggestions(SelectedCustomerName);
                    if (customerData != null)
                    {
                        SelectedCustomerList = new ObservableCollection<string>(customerData);
                    }
                    else
                        SelectedCustomerList = new ObservableCollection<string>();
                }
                catch (Exception ex)
                {
    
                }
            }
    
    
    private List<string> GetCustomerSuggestions(string text)
            {
                try
                {
                    return string.IsNullOrWhiteSpace(text) ? null : customers.Where(s => s.StartsWith(text, StringComparison.InvariantCultureIgnoreCase)).ToList();
                }
                catch (Exception)
                {
                    return null;
                }
            }
    
  • HarardinHarardin Member ✭✭
    edited July 2019
Sign In or Register to comment.