Can not get SfAutoComplete to bind to Object

Hello,

I am trying to use SfAutoComplete with data binding its source to Objects. I can not get values and I receive (in Visual Studio 2019) Xaml binding failure.

SfAutoComplete.AutoCompleteSource List`1 'System.Collections.Generic.List`1[ExpenseTracker.Model.Account]' cannot be converted to type 'System.Collections.Generic.List`1[System.String]'

My Object is defined in Model and bindings works because on same Page i have picker and it is populated with Object (ObservableCollection). I am using FreshMVVM. Does anyone have any solution?

My XAML code (page)

xmlns:autocomplete="clr-namespace:Syncfusion.SfAutoComplete.XForms;assembly=Syncfusion.SfAutoComplete.XForms"


xmlns:ListCollection="clr-namespace:System.Collections.Generic;assembly=netstandard"

xmlns:inputLayout="clr-namespace:Syncfusion.XForms.TextInputLayout;assembly=Syncfusion.Core.XForms"

xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"

xmlns:expensetracker="clr-namespace:ExpenseTracker"

x:Class="ExpenseTracker.SettingsPage">



SuggestionMode="Contains"

AutoCompleteMode="SuggestAppend"

AutoCompleteSource="{Binding Accounts}">


FontSize="20"

VerticalTextAlignment="Center"

HorizontalOptions="Center"

VerticalOptions="Center"

TextColor="#006bcd" />



ItemDisplayBinding="{Binding AccountName}"/>


ViewModel (PageModel in FreshMVVM)

using ExpenseTracker.Model;

using ExpenseTracker.Services;

using FreshMvvm;

using System;

using System.Collections.Generic;

using System.Collections.ObjectModel;

using System.Text;

using System.Threading.Tasks;


namespace ExpenseTracker

{

class SettingsPageModel : FreshBasePageModel

{

public async override void Init(object initData)

{

await LoadAllData();

}


// Tasks

async Task LoadAllData()

{

DatabaseConnection database = await DatabaseConnection.Instance;

var a = await database.GetAllAccounts();


//testing

a.Add(new Account() { AccountID = 0, AccountName = "Test1", AccountType = "Type1" });

a.Add(new Account() { AccountID = 1, AccountName = "Test2", AccountType = "Type2" });

a.Add(new Account() { AccountID = 2, AccountName = "Test3", AccountType = "Type1" });

a.Add(new Account() { AccountID = 3, AccountName = "Test4", AccountType = "Type1" });

// End of testing


Accounts = new ObservableCollection(a);

var c = await database.GetAllCategories();

Categories = new ObservableCollection(c);

}


// Properties


private ObservableCollection accounts;

public ObservableCollection Accounts

{

get => accounts;

set

{

accounts = value;

RaisePropertyChanged();

}

}


private ObservableCollection categpries;

public ObservableCollection Categories

{

get => categpries;

set

{

categpries = value;

RaisePropertyChanged();

}

}

}

}


4 Replies 1 reply marked as answer

JK Jeya Kasipandi Syncfusion Team November 8, 2021 12:57 PM UTC

Hi Gregor,

Currently, we are validating on this and will update details on November 09, 2021.We appreciate your patience until then.

Regards,
Jeya K




SS Suganya Sethuraman Syncfusion Team November 10, 2021 05:58 AM UTC

Hi Gregor,

We have analyzed the reported issue. We have prepared sample based on the information provided but we could not be able to reproduce the issue. Please have a sample and screenshot for your reference,

Sample: https://www.syncfusion.com/downloads/support/directtrac/general/ze/AutoCompleteFreshMVVM1454600476

Since we are not aware of your exact application scenario, so we request you to check the issue with the attached sample and let us know whether it is reproduced or not? If the issue was not reproduced in this sample, please revert us by modifying the sample based on your application along with replication procedure or provide the sample. It will help us to provide better solution at the earliest.

Regards,
Suganya Sethuraman.
 


Marked as answer

GR Gregor November 10, 2021 10:18 PM UTC

Thank you for provided example. After analyzing I was able to found an error - I was using  AutoCompleteSource and not DataSource. 



SS Suganya Sethuraman Syncfusion Team November 11, 2021 05:57 AM UTC

Hi Gregor,

Thanks for the update.

We are glad that your issue is resolved. Please let us know if you require any further assistance.

Regards,
Suganya Sethuraman.
 


Loader.
Up arrow icon