How do you access a native view from a MAUI control?
Short answer
Through the control's Handler.PlatformView, cast to the native type for the current platform (guarded by #if). This lets you call native APIs the cross-platform surface doesn't expose. Access it after the handler is created (e.g., in HandlerChanged).
Advertisement
AModel answer
Through the control's Handler.PlatformView, cast to the native type for the current platform (guarded by #if). This lets you call native APIs the cross-platform surface doesn't expose. Access it after the handler is created (e.g., in HandlerChanged).
myEntry.HandlerChanged += (s, e) =>
{
#if ANDROID
var native = (Android.Widget.EditText)myEntry.Handler.PlatformView;
native.SetSelectAllOnFocus(true);
#endif
};Real-world example
A form selects all text when an Entry gains focus on Android by reaching the native EditText via the handler.
Likely follow-ups
- When is PlatformView available? | Why guard with #if?
Related topics