Hi FernandoManuelGonalves-7609,
Welcome to our Microsoft Q&A platform!
I test both List<Encomenda>
and IEnumerable<Encomenda>
, and both of them work fine.
Here is my Database class.
class Database
{
public static SQLiteAsyncConnection db;
static async Task Init()
{
if (db != null)
return;
var databasePath = Path.Combine(FileSystem.AppDataDirectory, $"data.db");
db = new SQLiteAsyncConnection(databasePath);
await db.CreateTableAsync<Encomenda>();
}
public static async Task AddEncomenda(string encID, DateTime encData)
{
await Init();
var encomenda = new Encomenda
{
EncID = encID,
EncData = encData
};
await db.InsertAsync(encomenda);
}
public static async Task<IEnumerable<Encomenda>> GetEncomendaAsync()
{
await Init();
var encomenda = await db.Table<Encomenda>().ToListAsync();
var sortedencomenda = encomenda.OrderBy(x => x.EncData).ToList();
return sortedencomenda;
}
}
XAML:
<StackLayout>
<Button Text="Get items" Clicked="Button_Clicked"/>
<Picker x:Name="MyPicker"
ItemDisplayBinding="{Binding EncID}" />
</StackLayout>
xaml.cs
private async void Button_Clicked(object sender, EventArgs e)
{
var items = await Database.GetEncomendaAsync();
MyPicker.ItemsSource = (System.Collections.IList)items;
}
Regards,
Kyle
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.