dotnet / dotnet/docs-maui

What handler / mapper to call `AppendMapping` on?

Open
#2,045 1 comment 0 reactions 0 assignees View on GitHub
doc-enhancement dotnet-maui/subsvc dotnet-mobile/svc Pri2
Dominant language
No language data
Stars
282
Forks
265
Avg merge
2d 2h
Merged PRs (30d)
19

Description

### 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](https://learn.microsoft.com/en-us/dotnet/maui/user-interface/handlers/customize?view=net-maui-8.0#customize-a-control)) 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` and `ElementHandler` is?
- what the difference between `EntryHandler.Mapper` and `ElementHandler.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**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.