docs-maui
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
EntryHandler
andElementHandler
is? - what the difference between
EntryHandler.Mapper
andElementHandler.ElementMapper
is?
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.ElementMapper
should be used for custom-defined properties in an inherited class (e.g. if you addCornerRadius
yourself to a subclass ofEntry
). A custom-definedCornerRadius
mapping is not called viaEntryHandler.Mapper
for me (CornerRadius
is not implemented on the out-of-the-boxEntry
class). -
EntryHandler.Mapper
should be used for built-in properties from the "built-in properties" likeBackgroundColor
orIsEnabled
. The mappings for these properties do not work for me if I configure them usingElementHandler.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?