I've got stuck with this, and am very new to Xamatin Forms.
(I also posted this Friday but can find no trace of it???)
I'm wanting to use the AutoSuggestBox from dotMorten in my Xamarin Forms app.
I have the list of values in a SQLite table:
public class Streets
{
[PrimaryKey]
[MaxLength(255)]
public String StreetName { get; set; }
}
I'm wanting to use this table as the ItemsSource for the AutoSuggestBox but, using the ToDo example have this code to get the data from the table:
public Task<List<Streets>> LookupStreetsAsync(String query)
{
return lookups.Table<Streets>().Where(s => s.StreetName.StartsWith(query)).OrderBy(s => s.StreetName).ToListAsync();
}
However I cannot use this as the ItemsSource
private void StreetAutoSuggestBox_TextChanged(AutoSuggestBox sender, AutoSuggestBoxTextChangedEventArgs e)
{
if (e.Reason == AutoSuggestionBoxTextChangeReason.UserInput)
{
String query = sender.Text.Trim();
// only auto suggest if 3 or more characters
if (query.Length > 2)
{
sender.ItemsSource = App.Lookups.LookupStreetsAsync(query);
}
}
}
I get an error at sender.ItemsSource:
Cannot implicitly convert type 'System.Threading.Tasks.Task<System.Collections.Generic.List<XamarinFirst.Streets>>' to 'System.Collections.IList'. An explicit conversion exists (are you missing a cast?)
I have tried casting it to an IList but nothing I find Googling works, just different errors.
How can I use my SQLite table as the ItemsSource?
Thanks,
Mike