(Realm) Bind Picker to IEnumerable<T>

Fahmi Lestian Ramdhani 1 Reputation point
2023-01-04T02:02:01.773+00:00

Hi everyone,

I want to ask how to Bind Picker to IEnumerable<T>. I am using Realm for local database in MAUI android project. Based on Realm's guidance (Data Binding), Realm advises against using ToList(). Therefore, in my ViewModel I design it like this:

C#

public IEnumerable<Employee> Employees { get; }  
...  
  
Employees = realm. All<Employee>();  

In XAML

<Picker Title="Choose Employee" ItemsSource="{Binding Employees}" ItemDisplayBinding="{Binding Name}" SelectedItem="{Binding SelectedEmployee}" />  

By design above, XAML fails to fetch data from IEnumerable<Employee>. Even though the Employees property is filled with data from the results of realm.All<Employee>();

However, if a design like this works.
Its Work
C#

public IEnumerable<Employee> Employees { get; }  
...  
  
Employees = new List<Employee>(realm. All<Employee>());  

Is this a bug of MAUI or is it my fault?

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,856 questions
0 comments No comments
{count} votes