.NET MAUI Handler
Before learning.net maui handler you should know about .Net MAUI.
Please, support my blog by clicking on our sponsors ad!
This is explain in this video
In xamarin forms, we are using renderer to customize the controls, this renderers are code in all project to update the property, but now .net MAUI has come with single project so it is providing handler to customize the control, so we are using handler instead of renderer in .net maui.
What is Handler and Mappers?
Mappers
Mappers are a key concept in .NET MAUI handlers, usually providing a property mapper and sometimes a command mapper, which maps the cross-platform control’s API to the native view’s API.This mappers used dictionary to store the data.
Handler
It is a concept of maping cross platform control to native controls.
Each control has an interface, each control that implement interface is called virtual views. Handler map this virtual views to control of each platform control which is known as native views.
Handler main task is to map cross platform controls property, command to native's control property,command.
for example:
On IOS device, crossplatform button handler will map IOS button control, On Android device, crossplatform button handler will map AppCompactButton
Handler use Interface to access platform specific control.
All handlers are in Microsoft.Maui.Handlers accept:
- CarouselViewHandler and CollectionViewHandler are define in Microsoft.Maui.Control.Handler.Item
- LineHandler, PathHandler, PolygonHandler, PolylineHandler, RectangleHandler and RoundRectangleHandler are in the Microsoft.Maui.Controls.Handlers
- AppendToMapping: modifications done via this method will be run after an existing property mapping.
- PrependToMapping: modifications done here will be run before an existing mapping.
- ModifyMapping: modifies an existing mapping.
#if __ANDROID__
Microsoft.Maui.Handlers.ViewHandler.ViewMapper.AppendToMapping(nameof(IView.Background), (h, v) =>
{
(h.NativeView as Android.Views.View).SetBackgroundColor(Microsoft.Maui.Graphics.Colors.Red.ToNative());
});
#endif
PrependToMapping & ModifyMapping
#if __ANDROID__
This is explain in this video
Hope you understand this, Please share this blog and share your suggestion. Thanks for reading.
Comments
Post a Comment