Auto Complete using Xamarin Forms in C#

Hi,

I am trying to create a AutoComplete Text Entry using Xamarin Forms.
Can anybody help me in creating a custom renderer for the auto complete text field in C#.
I am using MVVM concept.

Posts

  • Xamarin.Form Labs does have it, but it is just a beta version. You can try it here: https://github.com/XLabs/Xamarin-Forms-Labs

  • NagashreeNagashree USMember

    This has a renderer for listview. I want some help in Auto Complete for a EntryText.

  • Hi,

    I've tried this example. And it works almost fine excepting - if I ty to access to SelectemItem field from the code it throws an exception:

    var item = customersView.SelectedItem;

    Of course I can read value of Text property and try to detected what item is selected, but it's option I like.

    Any ideas?

    Thanks.

  • Usha.8163Usha.8163 USMember ✭✭

    Hi,

    Is there any solution found for the above problem?

  • Golf.1650Golf.1650 USMember

    someone has managed to change the Text property in runtime?

  • When I try to set SelectedItem property in runtime it does not crash, however it does not work.
    Did someone manage to make it work? (I need this for setting value from previous user session)

    Thanks in advance.

  • @Usha.8163 said:
    Hi,

    Is there any solution found for the above problem?

    It works in the latest sources.

  • Any Solution for achieving AutoComplete in entry(text) field of xamarin forms?

  • Xlabs Autocomplete has issue in binding suggestions in the suggestion list.. I have used textchanged event to load the suggestion list.. Any Solution??

  • Naveed.0537Naveed.0537 USMember
    edited December 2016
  • XoffXoff FRMember

    The link you provided is form Xamarin platform, the need here is for forms!

  • BjornBBjornB USMember ✭✭✭
    edited June 2017

    @Xoff

    Here's a simple renderer, works great :)

    //AutoCompleteEntry is just a class inheriting Entry
    public  class AutoCompleteEnrtryRenderer : ViewRenderer<AutoCompleteEntry, AutoCompleteTextView>
        {     
             protected override void OnElementChanged(ElementChangedEventArgs<AutoCompleteEntry> e)
            {
                base.OnElementChanged(e);
    
                if (e.NewElement != null)
                {
                    if (Control == null)
                    {
                        var control = new AutoCompleteTextView(Xamarin.Forms.Forms.Context);
    
                        if (!string.IsNullOrEmpty(e.NewElement.Placeholder))
                            control.Hint = e.NewElement.Placeholder;
    
                        SetNativeControl(control);
                    }
    
                    UpdateAdapter();
                }
            }     
    
            private void UpdateAdapter()
            {
                var autoCompleteOptions = new String[] { "Malmö, Skåne", "Malmö kommun, Skåne" };
                ArrayAdapter autoCompleteAdapter = new ArrayAdapter(Xamarin.Forms.Forms.Context, Android.Resource.Layout.SimpleDropDownItem1Line, autoCompleteOptions);
                Control.Adapter = autoCompleteAdapter;
            }
        }
    
  • mostafa90mostafa90 USMember ✭✭

    @BjornB any hints how can i create a bindable object to the adabter?

  • BjornBBjornB USMember ✭✭✭

    You could create a list of strings as a bindableproperty, and listen to propertychanged in the renderer for that prop, when that changes update the adapter.

    I think this will get you started https://mindofai.github.io/Creating-Custom-Controls-with-Bindable-Properties-in-Xamarin.Forms/

  • AlmaJensen.9398AlmaJensen.9398 USMember ✭✭✭

    Check out SyncFusion. They've got a nice AutoComplete Entry field I've been using for a couple of apps and they have a free community edition that you may qualify for. If not their pricing is by far the best I've seen if you need to buy a license. They're library of controls in general is pretty much the best 3rd party set I've seen for Xamarin Forms.

    And a friendly suggestion about Xlabs run away as fast as you can. Community support for that has fallen so far to the wayside that anything I've ever used from that has been nothing but trouble.

  • CostasAletrariCostasAletrari USMember ✭✭

    Yep SyncFusion is fantastic, heaps of controls, Take the time and follow the instructions for installation. They work really well.
    and its FREE!! if your revenue is less than 1 Million dollars!

  • KrunalBagadiaKrunalBagadia USMember

    @BjornB , Thank You.
    Great your Solution work Perfactly , Can you Please Provide how can i handle it on IOS?

  • ask_himanshuask_himanshu Member ✭✭

    @BjornB how do I dynamically set list in autocomplete and also what should I do for ios app can you suggest me on this I urgently need this in my project

  • GeerShuangGeerShuang USMember ✭✭

    Other than the free trial version, I don't see a free licensing model for SyncFusion Xamarin on https://www.syncfusion.com/products/xamarin. Am I missing somehting?

  • seanydaseanyda GBMember ✭✭✭✭✭

    @GeerShuang said:
    Other than the free trial version, I don't see a free licensing model for SyncFusion Xamarin on https://www.syncfusion.com/products/xamarin. Am I missing somehting?

    You'll be looking for this -
    https://www.syncfusion.com/products/communitylicense

  • GeerShuangGeerShuang USMember ✭✭

    Thank you @seanyda I will look into that.

  • dotMortendotMorten USMember ✭✭

    You can also try my AutoSuggestBox here (there's a link there to the NuGet as well): https://github.com/dotMorten/XamarinFormsControls/tree/master/AutoSuggestBox

    Hopefully you'll find it useful. It's using native controls under the covers, and matches the behavior of the UWP AutoSuggestBox control closely (which means you'll have to filter and update the ItemSource yourself on TextChanged, but I found that gives the most flexibility for a various set of scenarios):

  • MuhammadAbuMandourMuhammadAbuMandour USMember ✭✭

    @dotMorten said:
    You can also try my AutoSuggestBox here (there's a link there to the NuGet as well): https://github.com/dotMorten/XamarinFormsControls/tree/master/AutoSuggestBox

    Hopefully you'll find it useful. It's using native controls under the covers, and matches the behavior of the UWP AutoSuggestBox control closely (which means you'll have to filter and update the ItemSource yourself on TextChanged, but I found that gives the most flexibility for a various set of scenarios):

    i used it but i have some problem for sorry

  • dotMortendotMorten USMember ✭✭
    I'd like to help you but you're not giving any information about what sort of problem you're hitting or what you were trying to do
  • wyepezwyepez Member
    edited August 2018

    I tried it and it works pretty well.

  • gregmatthewsgregmatthews GBMember ✭✭

    @dotMorten this looks perfect for me, got it all coded in just one newbie question, when I build I get
    Type AutoSuggestBox not found in xmlns http://xamarin.com/schemas/2014/forms

    I presume I need some extra xmlns: stuff at the top of my XAML page?

    <TabbedPage xmlns="http://xamarin.com/schemas/2014/forms" BarBackgroundColor="#0e3c63" BarTextColor="White"
                 xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
                 xmlns:local="clr-namespace:SparkEVX4;assembly=SparkEVX4.Android;"             
                 x:Class="SparkEVX4.MainPage">
    
  • gregmatthewsgregmatthews GBMember ✭✭

    @dotMorten is there a way to trigger a function when focus is put on the control? the aim would be that when it gets focus the dropdown shows a list of suggested entries, and when they type it then uses the _TextChanged to show autocomplete suggestions that match their text. It tried adding a Focused="AutoComplete_Focused" to the XAML, but couldn't get it to work with a function - always got a signature mismatch.

  • gregmatthewsgregmatthews GBMember ✭✭

    Answered one of my own questions (by reading the example, doh!)
    xmlns:dm="clr-namespace:dotMorten.Xamarin.Forms;assembly=dotMorten.Xamarin.Forms.AutoSuggestBox"

    <dm:AutoSuggestBox x:Name="staticSuggestBox"  
                                 PlaceholderText="Enter a country"  
                                 TextChanged="staticSuggestBox_TextChanged" 
                                 QuerySubmitted="SuggestBox_QuerySubmitted" /> 
    
  • gregmatthewsgregmatthews GBMember ✭✭

    @dotMorten the line spacing on the drop-down is quite widely spaced, is there a way to control it?

  • dotMortendotMorten USMember ✭✭

    @gregmatthews Please log an issue in the GitHub repo with screen shots and specifics on platform/device etc.

  • gregmatthewsgregmatthews GBMember ✭✭

    Thanks - will do

  • ShriGuruBaskarShriGuruBaskar USMember ✭✭
    edited March 14

    @dotMorten ,

    I'm using Xamarin forms , and autosuggestbox inside of a popup (3 consecutive autosuggestbox) , and i fill the itemsource property of all the three. But when i type in the box , i dont get a suggestionlist.

    It works fine in android , but not working in iOS.

    Your help is very much appreciated.

    I tried reducing the autosuggestbox to one but still autosuggestion does not appear.

    Thanks ,
    Shri Guru

  • dotMortendotMorten USMember ✭✭

    @Shri Could you please log a bug at https://github.com/dotMorten/XamarinFormsControls with a sample reproducing the issue, and I'll be happy to take a look.

Sign In or Register to comment.