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
var c = await database.GetAllCategories();
Categories = new ObservableCollection
}
// Properties
private ObservableCollection
public ObservableCollection
{
get => accounts;
set
{
accounts = value;
RaisePropertyChanged();
}
}
private ObservableCollection
public ObservableCollection
{
get => categpries;
set
{
categpries = value;
RaisePropertyChanged();
}
}
}
}
Thank you for provided example. After analyzing I was able to found an error - I was using AutoCompleteSource and not DataSource.