docs-maui
                                
                                 docs-maui copied to clipboard
                                
                                    docs-maui copied to clipboard
                            
                            
                            
                        What handler / mapper to call `AppendMapping` on?
Type of issue
Missing information
Description
In https://github.com/gzadro/.NET-MAUI-custom-Entry-control, the mapping code is run by calling Microsoft.Maui.Handlers.ElementHandler.ElementMapper.AppendToMapping(IView, Action):
https://github.com/gzadro/.NET-MAUI-custom-Entry-control/blob/f3dea0697762e6c8492a8259f71dc77ee3c78285/CustomInputMaui/MauiProgram.cs#L24-L30
In the Map method, the handler is being cast to an IEntryHandler after all:
https://github.com/gzadro/.NET-MAUI-custom-Entry-control/blob/f3dea0697762e6c8492a8259f71dc77ee3c78285/CustomInputMaui/Platforms/Android/CustomEntryMapper.cs#L21-L22
Looking at the API, I would find it more intuitive to use Microsoft.Maui.Handlers.EntryHandler.Mapper.AppendToMapping(IEntry, Action) (like in the documentation about handlers) but it seems to stop functioning when I use that method. If that downside would not be there, then it would be possible to avoid the casting.
I can't find documentation on where the difference is explained, though.
Can you please explain
- what the difference between EntryHandlerandElementHandleris?
- what the difference between EntryHandler.MapperandElementHandler.ElementMapperis?
Page URL
https://learn.microsoft.com/en-us/dotnet/maui/user-interface/handlers/customize?view=net-maui-8.0
Content source URL
https://github.com/dotnet/docs-maui/blob/main/docs/user-interface/handlers/customize.md
Document Version Independent Id
70227b04-808f-1370-186b-10cfef525959
Article author
@davidbritch
Metadata
- ID: 659665da-2ff3-3550-2e0c-20902c15c3e6
- Service: dotnet-mobile
- Sub-service: dotnet-maui
Update - for me, empirically it seems that:
- ElementHandler.ElementMappershould be used for custom-defined properties in an inherited class (e.g. if you add- CornerRadiusyourself to a subclass of- Entry). A custom-defined- CornerRadiusmapping is not called via- EntryHandler.Mapperfor me (- CornerRadiusis not implemented on the out-of-the-box- Entryclass).
- EntryHandler.Mappershould be used for built-in properties from the "built-in properties" like- BackgroundColoror- IsEnabled. The mappings for these properties do not work for me if I configure them using- ElementHandler.ElementMapper.
It would really help me to have this explicitly documented though, as I'm not sure if this is the intended behavior, and if so - how should people know what property to map where?