How do you customize a control on a single platform using a handler?
Short answer
Use PropertyMapper customization scoped by checking the view instance, or subclass the handler for that control and register it. AppendToMapping adds behavior after the default; ModifyMapping replaces a specific property's mapping. Guard native calls with platform #if.
Advertisement
AModel answer
Use PropertyMapper customization scoped by checking the view instance, or subclass the handler for that control and register it. AppendToMapping adds behavior after the default; ModifyMapping replaces a specific property's mapping. Guard native calls with platform #if.
#if IOS
Microsoft.Maui.Handlers.SwitchHandler.Mapper.AppendToMapping(
"Tint", (h, v) => h.PlatformView.OnTintColor =
UIKit.UIColor.SystemGreenColor);
#endifReal-world example
Product design wants iOS switches tinted brand-green; a single iOS-guarded mapper achieves it without touching Android.
Likely follow-ups
- AppendToMapping vs ModifyMapping? | How do you scope to one control instance?
Related topics