dotnet / MobileBlazorBindings

Experimental Mobile Blazor Bindings - Build native and hybrid mobile apps with Blazor
MIT License
1.2k stars 168 forks source link

Update Picker.ItemDisplayBinding to be Func instead of string #460

Open Dreamescaper opened 2 years ago

Dreamescaper commented 2 years ago

Currently in our Picker implementation ItemDisplayBinding property has a string type, which represents property name which should be displayed, so if I have the following item type:

class Item
{
    public string Id {get;set;}
    public string Name {get;set;}
}

I can use ItemDisplayBinding="Name" so Picker would use this property for items.

But a) It has no compile time validation b) It's not flexible. What if I want to use multiple properties for display item or use custom function?

It should be Func instead (ItemDisplayBinding="i => i.Name"). We can use Maui's TypedBinding to convert Func to Binding to be able to assign it to Maui's control.

One thing I'm not sure about is naming. Does it make sense to rename it to smth like ItemDisplaySelector? Since it has no relation to Maui's Bindings? Or leave it as is?