We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

How to Bind using MVVM?

1) I tried your sample codeherein the documentation but it doesnt work. How are supposed to do binding?
2) This tool is only working I think when data is loaded inside constructor of the viewmodel. Once tool appears in the view, It is not possible to bind if even I raise a property changed.

5 Replies

PK Pavendhan Kumar Syncfusion Team November 21, 2016 12:08 PM UTC

Hi Emil,

Thank you for your update.

We would like to know whether you are trying to add AutoCompleteSource dynamically?. Because currently SfAutoComplete did not supports dynamic source updation.

Regards,
Pavendhan K.


EM Emil November 21, 2016 04:03 PM UTC

I tried first dynamically but I guessed that it doesnt work because I experienced from sfrotator. Then i tried like in the documentation. I wrote exactly same code but no chance. Here is my code how I tried it


In xaml I defined AutoComlete as below with the Datasource binding and  Name as DisplayMemberPath

<autocomplete:SfAutoComplete x:Name="autocomplete" Watermark="Enter a name" MinimumPrefixCharacters="3" MaximumDropDownHeight="200" 
                                 AutoCompleteMode="Suggest" SuggestionMode="Contains" DataSource="{Binding AllItems}"  HeightRequest="60" 
                           SelectedValuePath="Id"      DisplayMemberPath="Name">      
    </autocomplete:SfAutoComplete>

In my View Model and its constructor, I get all the items;

  public  class ItemsViewModel
 public ItemsViewModel()
        {
              var Items = await db.getAllItemsAsync(recursive: false);
            AllItems = new ObservableCollection<ItemList>(Items));
            RaisePropertyChanged("AllItems");
            return cacheItems;
        }
}

Then I assign BindingContext in the constructor of the page but it doesnt unfortunately work. I tried using ItemItemSource binding as well but it doesnt work

     autocomplete.BindingContext = new ItemsViewModel();

my Model

     public class Item
    {
        [PrimaryKey, AutoIncrement, Unique, NotNull]
        public int Id { get; set; }

        [MaxLength(255)]
        public string Name { get; set; }
    }

I checked your sample app called "SampleBrowser-Forms" but there example is based on String list not with object list. What am I doing wrong?


PK Pavendhan Kumar Syncfusion Team November 22, 2016 10:20 AM UTC

Hi Emil,

Thank you for your update. We have prepared a sample as per your requirement please download the same from the following link.

Sample Link: http://www.syncfusion.com/downloads/support/forum/127507/ze/AutoCompleteDataSource1218473721 

Please let us know whether the sample meets your requirement or not.

Regards,
Pavendhan K.
 



NI Nishant July 14, 2017 02:19 AM UTC

Request it to make sfautocomplete dynamic... like on user start typing we can go to the server and check for related data.


Thanks 



VA Vanaja  Annasamy Syncfusion Team July 14, 2017 05:00 PM UTC

Hi Emil,

Thank you for the update.

We have created SfAutoComplete sample based on your requirement to add data dynamically using DataSource. Please download the same from below link.

Link:  http://www.syncfusion.com/downloads/support/forum/127507/ze/AutoComplete-564205971 

Please run the sample and check whether it meets your requirement. If not please provide the detailed description of your requirement and it will help us to proceed further with the same.

Regards,
Vanaja R.A. 


Loader.
Up arrow icon